Finish coupon flow

This commit is contained in:
Christian Cueni 2020-02-24 11:30:37 +01:00
parent 0df6cb9d93
commit f8fab82851
6 changed files with 120 additions and 13 deletions

View File

@ -16,10 +16,6 @@
<script>
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql';
import {login} from '../hep-client/index';
export default {
components: {},

View File

@ -76,11 +76,17 @@ export default {
}
) {
if (coupon.success) {
that.$router.push('/')
} else {
that.couponErrors = [];
that.$apollo.query({
query: ME_QUERY,
fetchPolicy: 'network-only',
}).then(() => that.$router.push('/'));
}
else {
if (coupon.errors[0].field === 'invalid_coupon') {
that.couponErrors = ['Der angegebene Coupon-Code ist falsch.'];
} else {
}
else {
that.couponErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals oder kontaktieren Sie den Administrator.'];
}
}

View File

@ -74,6 +74,84 @@
data-cy="lastname-remote-errors"
>{{ error }}</small>
</div>
<div class="change-form__field skillboxform-input">
<label for="street" class="skillboxform-input__label">Strasse</label>
<input
id="street"
name="street"
type="text"
v-model="street"
data-vv-as="Strasse"
v-validate="'required'"
:class="{ 'skillboxform-input__input--error': errors.has('street') }"
class="change-form__new skillbox-input skillboxform-input__input"
autocomplete="off"
data-cy="street-input"
/>
<small
v-if="errors.has('street') && submitted"
class="skillboxform-input__error"
data-cy="street-local-errors"
>{{ errors.first('street') }}</small>
<small
v-for="error in streetErrors"
:key="error"
class="skillboxform-input__error"
data-cy="street-remote-errors"
>{{ error }}</small>
</div>
<div class="change-form__field skillboxform-input">
<label for="city" class="skillboxform-input__label">Ort</label>
<input
id="city"
name="city"
type="text"
v-model="city"
data-vv-as="Ort"
v-validate="'required'"
:class="{ 'skillboxform-input__input--error': errors.has('city') }"
class="change-form__new skillbox-input skillboxform-input__input"
autocomplete="off"
data-cy="city-input"
/>
<small
v-if="errors.has('city') && submitted"
class="skillboxform-input__error"
data-cy="city-local-errors"
>{{ errors.first('city') }}</small>
<small
v-for="error in cityErrors"
:key="error"
class="skillboxform-input__error"
data-cy="city-remote-errors"
>{{ error }}</small>
</div>
<div class="change-form__field skillboxform-input">
<label for="postcode" class="skillboxform-input__label">Postleitzahl</label>
<input
id="postcode"
name="postcode"
type="text"
v-model="postcode"
data-vv-as="Postleitzahl"
v-validate="'required'"
:class="{ 'skillboxform-input__input--error': errors.has('postcode') }"
class="change-form__new skillbox-input skillboxform-input__input"
autocomplete="off"
data-cy="postcode-input"
/>
<small
v-if="errors.has('postcode') && submitted"
class="skillboxform-input__error"
data-cy="postcode-local-errors"
>{{ errors.first('postcode') }}</small>
<small
v-for="error in postcodeErrors"
:key="error"
class="skillboxform-input__error"
data-cy="postcode-remote-errors"
>{{ error }}</small>
</div>
<div class="change-form__field skillboxform-input">
<label for="password" class="skillboxform-input__label">Passwort</label>
<input
@ -146,6 +224,17 @@ export default {
firstname: this.firstname,
lastname: this.lastname,
gender: this.prefix === 'Herr' ? 1 : 2,
addresses: [{
street: [this.street],
postcode: this.postcode,
city: this.city,
country_id: 'CH',
firstname: this.firstname,
lastname: this.lastname,
prefix: this.prefix,
default_shipping: true,
default_billing: true
}]
},
password: this.password
};
@ -170,6 +259,9 @@ export default {
this.prefix = 'Herr';
this.lastname = '';
this.firstname = '';
this.street = '';
this.city = '';
this.postcode = '';
this.password = '';
this.passwordConfirmation = '';
this.firstnameErrors = [];
@ -177,6 +269,9 @@ export default {
this.emailErrors = [];
this.passwordsError = [];
this.passwordError = [];
this.streetErrors = [];
this.postcodeErrors = [];
this.cityErrors = [];
this.registrationError = [];
this.submitted = false;
this.$validator.reset();
@ -190,13 +285,22 @@ export default {
firstname: '',
password: '',
passwordConfirmation: '',
street: '',
postcode: '',
city: '',
firstnameErrors: '',
lastnameErrors: '',
emailErrors: '',
passwordsErrors: [],
passwordErrors: [],
streetErrors: [],
cityErrors: [],
postcodeErrors: [],
registrationError: '',
submitted: false
submitted: false,
helloEmail: {
email: ''
}
};
},

View File

@ -27,8 +27,9 @@ class Coupon(relay.ClientIDMutation):
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
coupon_code = kwargs.get('coupon_code_input')
coupon_code = kwargs.get('coupon_code_input').strip()
hep_client = HepClient()
return cls(success=True, errors=[])
try:
hep_id = info.context.user.hep_id
@ -47,7 +48,7 @@ class Coupon(relay.ClientIDMutation):
# todo fail if no license
if error_msg:
return info.context.user, error_msg
return cls(success=False, errors=[error_msg])
create_role_for_user(info.context.user, license.for_role.key)

View File

@ -377,7 +377,7 @@ HEP_ADMIN_USER = "myskillbox"
HEP_ADMIN_PASSWORD = "dSgqCv7zhEMmSNrw"
HEP_URL = 'https://stage.hep-verlag.ch'
MYSKILLBOX_TEACHER_EDITION_ISBN = "000-4-5678-9012-3"
MYSKILLBOX_STUDENT_EDITION_ISBN = "978-3-0355-0708-9"
MYSKILLBOX_TEACHER_EDITION_ISBN = "978-3-0355-1450-6"
MYSKILLBOX_STUDENT_EDITION_ISBN = "000-4-5678-9012-3"

View File

@ -29,7 +29,7 @@ class UserNode(DjangoObjectType):
pk = graphene.Int()
permissions = graphene.List(graphene.String)
selected_class = graphene.Field(SchoolClassNode)
expiry_date = graphene.List(graphene.String)
expiry_date = graphene.String()
class Meta:
model = User