Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

feat(default-theme): display 400 errors right from the API #572

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/default-theme/components/SwLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<div class="form sw-login__form">
<h2 class="sw-login__header">Log in</h2>
<SfAlert
v-if="error"
v-if="userError"
class="sw-login__alert"
type="danger"
message="Invalid credentials"
:message="userError"
/>
<SfInput
v-model="email"
Expand Down Expand Up @@ -47,7 +47,7 @@ import { required, email } from 'vuelidate/lib/validators'
import { useUser } from '@shopware-pwa/composables'

export default {
name: 'SwResetPassword',
name: 'SwLogin',
components: { SfButton, SfInput, SfAlert },
mixins: [validationMixin],
data() {
Expand All @@ -57,11 +57,11 @@ export default {
}
},
setup() {
const { login, loading, error } = useUser()
const { login, loading, error: userError } = useUser()
return {
clientLogin: login,
isLoading: loading,
error
userError
}
},
validations: {
Expand Down Expand Up @@ -94,7 +94,7 @@ export default {

.sw-login {
&__alert {
margin-bottom: var(--spacer-small);
margin-bottom: var(--spacer-big);
}
&__header {
margin-bottom: var(--spacer-big);
Expand Down
47 changes: 32 additions & 15 deletions packages/default-theme/components/forms/SwEmail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
Remember to keep your email up to date in case of loosing password.
</p>
</slot>

<SfAlert
v-if="error"
class="sw-personal-info__alert"
v-for="(message, index) in useUserErrorMessages"
:key="index"
class="sw-email__alert"
type="danger"
message="Errors in the form"
:message="message"
/>

<div class="sw-email__form form">
Expand All @@ -28,15 +28,15 @@
@blur="$v.email.$touch()"
/>
<SfInput
v-model="confirmEmail"
:valid="!$v.confirmEmail.$error"
v-model="emailConfirmation"
:valid="!$v.emailConfirmation.$error"
error-message="Must match first one"
type="email"
name="confirmEmail"
name="emailConfirmation"
label="Confirm e-mail"
class="form__element"
required
@blur="$v.confirmEmail.$touch()"
@blur="$v.emailConfirmation.$touch()"
/>
<SfInput
v-model="password"
Expand Down Expand Up @@ -67,44 +67,55 @@ import { validationMixin } from 'vuelidate'
import { required, email, sameAs } from 'vuelidate/lib/validators'
import { SfInput, SfButton, SfAlert } from '@storefront-ui/vue'
import { useUser } from '@shopware-pwa/composables'
import { getMessagesFromErrorsArray } from '@shopware-pwa/helpers'

export default {
name: 'MyProfile',
name: 'EmailChange',
components: { SfInput, SfButton, SfAlert },
mixins: [validationMixin],
props: {},
setup() {
const { user, error, updateEmail, refreshUser } = useUser()
const { user, error: userError, updateEmail, refreshUser } = useUser()
patzick marked this conversation as resolved.
Show resolved Hide resolved
return {
refreshUser,
updateEmail,
user,
error
userError,
getMessagesFromErrorsArray
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
userError,
getMessagesFromErrorsArray
userErrorMessages

}
},
data() {
return {
email: '',
confirmEmail: '',
emailConfirmation: '',
password: ''
}
},
computed: {
useUserErrorMessages() {
// all the 400 errors are in a raw format stright from the API - to be extracted easily depeding on needs.
return (
this.userError &&
this.getMessagesFromErrorsArray(this.userError.message)
)
}
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we don't need this computed section in components

methods: {
async invokeUpdate() {
const emailChanged = await this.updateEmail({
email: this.email,
confirmEmail: this.confirmEmail,
emailConfirmation: this.confirmEmail,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Michal-Dziedzinski tu jest fix

password: this.password
})
await refreshUser()
await this.refreshUser()
}
},
validations: {
email: {
required,
email
},
confirmEmail: {
emailConfirmation: {
required,
sameAsEmail: sameAs('email'),
email
Expand All @@ -119,6 +130,12 @@ export default {
<style lang="scss" scoped>
@import '~@storefront-ui/vue/styles.scss';

.sw-email {
&__alert {
margin-bottom: var(--spacer-big);
}
}

.form {
@include for-desktop {
display: flex;
Expand Down
30 changes: 24 additions & 6 deletions packages/default-theme/components/forms/SwPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
</slot>

<SfAlert
v-if="error"
class="sw-personal-info__alert"
v-for="(message, index) in useUserErrorMessages"
:key="index"
class="sw-password__alert"
type="danger"
message="Errors in the form"
:message="message"
/>

<div class="sw-password__form form">
Expand Down Expand Up @@ -70,19 +71,21 @@ import { validationMixin } from 'vuelidate'
import { required, minLength, sameAs } from 'vuelidate/lib/validators'
import { SfInput, SfButton, SfAlert } from '@storefront-ui/vue'
import { useUser } from '@shopware-pwa/composables'
import { getMessagesFromErrorsArray } from '@shopware-pwa/helpers'

export default {
name: 'SwPassword',
components: { SfInput, SfButton, SfAlert },
mixins: [validationMixin],
props: {},
setup() {
const { user, error, updatePassword, refreshUser } = useUser()
const { user, error: userError, updatePassword, refreshUser } = useUser()
return {
refreshUser,
updatePassword,
user,
error
userError,
getMessagesFromErrorsArray
}
},
data() {
Expand All @@ -93,14 +96,23 @@ export default {
email: this.user && this.user.email
}
},
computed: {
useUserErrorMessages() {
// all the 400 errors are in a raw format stright from the API - to be extracted easily depeding on needs.
return (
this.userError &&
this.getMessagesFromErrorsArray(this.userError.message)
)
}
},
methods: {
async invokeUpdate() {
const passwordChanged = await this.updatePassword({
password: this.password,
newPassword: this.newPassword,
newPasswordConfirm: this.newPasswordConfirm
})
await refreshUser()
await this.refreshUser()
}
},
validations: {
Expand All @@ -123,6 +135,12 @@ export default {
<style lang="scss" scoped>
@import '~@storefront-ui/vue/styles.scss';

.sw-password {
&__alert {
margin-bottom: var(--spacer-big);
}
}

.form {
@include for-desktop {
display: flex;
Expand Down
36 changes: 19 additions & 17 deletions packages/default-theme/components/forms/SwPersonalInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

<div class="sw-personal-info__form form">
<slot name="form">
<SfSelect
v-if="getMappedSalutations && getMappedSalutations.length > 0"
v-model="salutation"
label="Salutation"
:valid="!$v.salutation.$error"
error-message="Salutation must be selected"
class="sf-select--underlined form__element form__element--half form__select"
>
<SfSelectOption
v-for="salutationOption in getMappedSalutations"
:key="salutationOption.id"
:value="salutationOption"
<SfSelect
v-if="getMappedSalutations && getMappedSalutations.length > 0"
v-model="salutation"
label="Salutation"
:valid="!$v.salutation.$error"
error-message="Salutation must be selected"
class="sf-select--underlined form__element form__element--half form__select"
>
{{ salutationOption.name }}
</SfSelectOption>
</SfSelect>
<SfSelectOption
v-for="salutationOption in getMappedSalutations"
:key="salutationOption.id"
:value="salutationOption"
>
{{ salutationOption.name }}
</SfSelectOption>
</SfSelect>
<SfInput
v-model="title"
name="title"
Expand Down Expand Up @@ -112,7 +112,9 @@ export default {
error: salutationsError
} = useSalutations()

const getMappedSalutations = computed(() => mapSalutations(getSalutations.value))
const getMappedSalutations = computed(() =>
mapSalutations(getSalutations.value)
)

return {
fetchSalutations,
Expand Down Expand Up @@ -141,7 +143,7 @@ export default {
},
computed: {
getErrorMessage() {
return userError && !salutationsError
return this.userError && !this.salutationsError
? 'Cannot create a new account, the user may already exist'
: "Coudn't fetch available salutations or countries, please contact the administration."
}
Expand Down