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

Commit

Permalink
feat(default-theme): created and styled error list component
Browse files Browse the repository at this point in the history
* feat(default-theme): created and styled error list component
  • Loading branch information
Malwurf authored Sep 4, 2020
1 parent acde710 commit d0e3b42
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 98 deletions.
8 changes: 4 additions & 4 deletions packages/default-theme/cms/elements/CmsElementContactForm.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div>
<form
v-if="!formSent"
action=""
class="cms-element-contact-form"
@submit.prevent="submit"
v-if="!formSent"
>
<SfSelect
v-if="getMappedSalutations && getMappedSalutations.length > 0"
Expand Down Expand Up @@ -110,7 +110,7 @@
/>
</div>

<SfAlert v-if="errorMessage" :message="errorMessage" type="danger" />
<SwErrorsList :list="errorMessage" />

<SwButton class="send button">
{{ $t("send") }}
Expand All @@ -132,7 +132,6 @@ import {
SfSelect,
SfInput,
SfCheckbox,
SfAlert,
SfIcon,
SfHeading,
} from "@storefront-ui/vue"
Expand All @@ -149,6 +148,7 @@ import {
import { computed, ref } from "@vue/composition-api"
import SwButton from "@shopware-pwa/default-theme/components/atoms/SwButton"
import { sendContactForm } from "@shopware-pwa/shopware-6-client"
import SwErrorsList from "@shopware-pwa/default-theme/components/SwErrorsList"
export default {
name: "CmsElementContactForm",
Expand All @@ -157,7 +157,7 @@ export default {
SfInput,
SfCheckbox,
SwButton,
SfAlert,
SwErrorsList,
SfIcon,
SfHeading,
},
Expand Down
15 changes: 4 additions & 11 deletions packages/default-theme/cms/elements/CmsElementNesletterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@
/>
</transition>

<div v-if="errorMessage">
<SfAlert
v-for="(message, key) in errorMessage"
:key="key"
:message="message"
type="danger"
class="error-alert"
/>
</div>
<SwErrorsList :list="errorMessage" />

<span>
<SwButton
Expand All @@ -72,22 +64,23 @@
</template>

<script>
import { SfInput, SfHeading, SfAlert } from "@storefront-ui/vue"
import { SfInput, SfHeading } from "@storefront-ui/vue"
import { validationMixin } from "vuelidate"
import { required, email } from "vuelidate/lib/validators"
import SwButton from "@shopware-pwa/default-theme/components/atoms/SwButton"
import { newsletterSubscribe } from "@shopware-pwa/shopware-6-client"
import { ref } from "@vue/composition-api"
import { getApplicationContext } from "@shopware-pwa/composables"
import { getMessagesFromErrorsArray } from "@shopware-pwa/helpers"
import SwErrorsList from "@shopware-pwa/default-theme/components/SwErrorsList"
export default {
name: "CmsElementNewsletterForm",
components: {
SfInput,
SwButton,
SfHeading,
SfAlert,
SwErrorsList,
},
mixins: [validationMixin],
props: {
Expand Down
43 changes: 43 additions & 0 deletions packages/default-theme/components/SwErrorsList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div v-if="list" class="errors-list-component">
<SwAlert :message="$t('Encountered problems:')" type="danger" />

<ul class="list">
<li v-for="message in list" :key="message" class="item">{{ message }}</li>
</ul>
</div>
</template>

<script>
import SwAlert from "@shopware-pwa/default-theme/components/atoms/SwAlert"
export default {
name: "SwErrorsList",
components: { SwAlert },
props: {
list: {
type: Array,
default: [],
},
},
setup(props, { root }) {
return {}
},
}
</script>

<style lang="scss" scoped>
.errors-list-component {
color: var(--_c-red-primary);
font-size: var(--font-sm);
.list {
margin-top: var(--spacer-xs);
padding-left: var(--spacer-xs);
.item {
list-style: inside;
}
}
}
</style>
27 changes: 27 additions & 0 deletions packages/default-theme/components/atoms/SwAlert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<SfAlert :message="message" :type="type" />
</template>

<script>
import { SfAlert } from "@storefront-ui/vue"
export default {
name: "SwAlert",
components: {
SfAlert,
},
props: {
message: {
type: String,
default: "",
},
type: {
type: String,
default: "secondary",
},
},
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="log-in">
<div class="log-in__buttons-container">
<SwButton
@click="switchLoginModalState(true)"
class="log-in__button color-secondary"
@click="switchLoginModalState(true)"
>Log in to your account</SwButton
>
<SwPluginSlot name="checkout-login-after" />
Expand All @@ -15,31 +15,10 @@
title="1. Personal details"
class="sf-heading--left sf-heading--no-underline title"
/>
<SfAlert
v-for="(message, index) in useUserErrorMessages"
:key="index"
class="sw-checkout__personal_info__alert"
type="danger"
:message="message"
/>

<SwErrorsList :list="useUserErrorMessages" />

<div class="form">
<!-- <SfSelect
v-if="getMappedSalutations && getMappedSalutations.length > 0"
v-model="salutationId"
label="Salutation"
:valid="!validations.salutationId.$error"
@change="validations.salutationId.$touch()"
error-message="Salutation must be selected"
class="sf-select--underlined form__element form__element--salutation form__select"
>
<SfSelectOption
v-for="salutationOption in getMappedSalutations"
:key="salutationOption.id"
:value="salutationOption.id || ''"
>
{{ salutationOption.name }}
</SfSelectOption>
</SfSelect> -->
<SwInput
v-model="firstName"
label="First name"
Expand Down Expand Up @@ -132,7 +111,6 @@ import {
SfCharacteristic,
SfSelect,
SfProductOption,
SfAlert,
} from "@storefront-ui/vue"
import SwPluginSlot from "sw-plugins/SwPluginSlot"
import SwButton from "@shopware-pwa/default-theme/components/atoms/SwButton"
Expand Down Expand Up @@ -160,22 +138,20 @@ import {
usePersonalDetailsStep,
usePersonalDetailsStepValidationRules,
} from "@shopware-pwa/default-theme/logic/checkout/usePersonalDetailsStep"
import SwErrorsList from "@shopware-pwa/default-theme/components/SwErrorsList"
export default {
name: "PersonalDetailsGuestForm",
mixins: [validationMixin],
components: {
SwInput,
SfCheckbox,
SwButton,
SfHeading,
SfModal,
SfCharacteristic,
SfSelect,
SfProductOption,
SfAlert,
SwErrorsList,
SwPluginSlot,
},
mixins: [validationMixin],
props: {
order: {
type: Object,
Expand Down Expand Up @@ -257,6 +233,12 @@ export default {
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)
},
},
watch: {
createAccount(value) {
if (!value) this.password = ""
Expand All @@ -270,11 +252,28 @@ export default {
// },
$v: {
immediate: true,
handler: function () {
handler() {
this.setValidations(this.$v)
},
},
},
async mounted() {
// hack to register user without picking up the country (minimal registration)
await this.fetchCountries()
if (!this.getCountries) {
return
}
const pickedCountry = this.getCountries.find(
({ name }) => name === "Poland"
)
this.billingAddress.countryId = pickedCountry && pickedCountry.id
await this.fetchSalutations()
const defaultSalutation = this.getMappedSalutations[
this.getMappedSalutations.length - 1
]
this.salutationId = defaultSalutation && defaultSalutation.id
},
methods: {
async toShipping() {
// run the validators against the provided data
Expand Down Expand Up @@ -303,29 +302,6 @@ export default {
}
},
},
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)
},
},
async mounted() {
// hack to register user without picking up the country (minimal registration)
await this.fetchCountries()
if (!this.getCountries) {
return
}
const pickedCountry = this.getCountries.find(
({ name }) => name === "Poland"
)
this.billingAddress.countryId = pickedCountry && pickedCountry.id
await this.fetchSalutations()
const defaultSalutation = this.getMappedSalutations[
this.getMappedSalutations.length - 1
]
this.salutationId = defaultSalutation && defaultSalutation.id
},
// TODO: move all the rules globally
validations: {
...usePersonalDetailsStepValidationRules,
Expand Down
12 changes: 3 additions & 9 deletions packages/default-theme/components/forms/SwPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
</p>
</slot>

<SfAlert
v-for="(message, index) in userErrorMessages"
:key="index"
class="sw-password__alert"
type="danger"
:message="message"
/>
<SwErrorsList :list="userErrorMessages" />

<div class="sw-password__form form">
<slot name="form">
Expand Down Expand Up @@ -70,15 +64,15 @@
import { validationMixin } from "vuelidate"
import { required, minLength, sameAs } from "vuelidate/lib/validators"
import { computed } from "@vue/composition-api"
import { SfAlert } from "@storefront-ui/vue"
import { useUser } from "@shopware-pwa/composables"
import { getMessagesFromErrorsArray } from "@shopware-pwa/helpers"
import SwButton from "@shopware-pwa/default-theme/components/atoms/SwButton"
import SwInput from "@shopware-pwa/default-theme/components/atoms/SwInput"
import SwErrorsList from "@shopware-pwa/default-theme/components/SwErrorsList"
export default {
name: "SwPassword",
components: { SwInput, SwButton, SfAlert },
components: { SwInput, SwButton, SwErrorsList },
mixins: [validationMixin],
props: {},
setup(props, { root }) {
Expand Down
Loading

1 comment on commit d0e3b42

@vercel
Copy link

@vercel vercel bot commented on d0e3b42 Sep 4, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.