Commit 5da8300a authored by Vitaly Slobodin's avatar Vitaly Slobodin

Apply reviewer suggestions

parent 71e302cb
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
import { GlFormGroup, GlFormInput, GlFormSelect } from '@gitlab/ui'; import { GlFormGroup, GlFormInput, GlFormSelect } from '@gitlab/ui';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { STEPS } from 'ee/subscriptions/constants'; import { STEPS } from 'ee/subscriptions/constants';
import UPDATE_STATE from 'ee/subscriptions/graphql/mutations/update_state.mutation.graphql'; import updateStateMutation from 'ee/subscriptions/graphql/mutations/update_state.mutation.graphql';
import COUNTRIES_QUERY from 'ee/subscriptions/graphql/queries/countries.query.graphql'; import countriesQuery from 'ee/subscriptions/graphql/queries/countries.query.graphql';
import STATE_QUERY from 'ee/subscriptions/graphql/queries/state.query.graphql'; import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql';
import STATES_QUERY from 'ee/subscriptions/graphql/queries/states.query.graphql'; import statesQuery from 'ee/subscriptions/graphql/queries/states.query.graphql';
import Step from 'ee/vue_shared/purchase_flow/components/step.vue'; import Step from 'ee/vue_shared/purchase_flow/components/step.vue';
import { GENERAL_ERROR_MESSAGE } from 'ee/vue_shared/purchase_flow/constants'; import { GENERAL_ERROR_MESSAGE } from 'ee/vue_shared/purchase_flow/constants';
import createFlash from '~/flash'; import createFlash from '~/flash';
...@@ -24,45 +24,24 @@ export default { ...@@ -24,45 +24,24 @@ export default {
}, },
data() { data() {
return { return {
country: null, countries: [],
address1: null,
address2: null,
city: null,
state: null,
zipCode: null,
company: null,
}; };
}, },
apollo: { apollo: {
state: { customer: {
query: STATE_QUERY, query: stateQuery,
manual: true,
result({ data, loading }) {
if (loading) {
return;
}
const { customer } = data;
this.country = customer.country;
this.address1 = customer.address1;
this.address2 = customer.address2;
this.city = customer.city;
this.state = customer.state;
this.zipCode = customer.zipCode;
this.company = customer.company;
},
}, },
countries: { countries: {
query: COUNTRIES_QUERY, query: countriesQuery,
}, },
states: { states: {
query: STATES_QUERY, query: statesQuery,
skip() { skip() {
return !this.country; return !this.customer.country;
}, },
variables() { variables() {
return { return {
countryId: this.country, countryId: this.customer.country,
}; };
}, },
}, },
...@@ -70,15 +49,15 @@ export default { ...@@ -70,15 +49,15 @@ export default {
computed: { computed: {
countryModel: { countryModel: {
get() { get() {
return this.country; return this.customer.country;
}, },
set(country) { set(country) {
this.updateState({ customer: { country } }); this.updateState({ customer: { country, state: null } });
}, },
}, },
streetAddressLine1Model: { streetAddressLine1Model: {
get() { get() {
return this.address1; return this.customer.address1;
}, },
set(address1) { set(address1) {
this.updateState({ customer: { address1 } }); this.updateState({ customer: { address1 } });
...@@ -86,7 +65,7 @@ export default { ...@@ -86,7 +65,7 @@ export default {
}, },
streetAddressLine2Model: { streetAddressLine2Model: {
get() { get() {
return this.address2; return this.customer.address2;
}, },
set(address2) { set(address2) {
this.updateState({ customer: { address2 } }); this.updateState({ customer: { address2 } });
...@@ -94,7 +73,7 @@ export default { ...@@ -94,7 +73,7 @@ export default {
}, },
cityModel: { cityModel: {
get() { get() {
return this.city; return this.customer.city;
}, },
set(city) { set(city) {
this.updateState({ customer: { city } }); this.updateState({ customer: { city } });
...@@ -102,7 +81,7 @@ export default { ...@@ -102,7 +81,7 @@ export default {
}, },
countryStateModel: { countryStateModel: {
get() { get() {
return this.state; return this.customer.state;
}, },
set(state) { set(state) {
this.updateState({ customer: { state } }); this.updateState({ customer: { state } });
...@@ -110,7 +89,7 @@ export default { ...@@ -110,7 +89,7 @@ export default {
}, },
zipCodeModel: { zipCodeModel: {
get() { get() {
return this.zipCode; return this.customer.zipCode;
}, },
set(zipCode) { set(zipCode) {
this.updateState({ customer: { zipCode } }); this.updateState({ customer: { zipCode } });
...@@ -118,10 +97,10 @@ export default { ...@@ -118,10 +97,10 @@ export default {
}, },
isValid() { isValid() {
return ( return (
!isEmpty(this.country) && !isEmpty(this.customer.country) &&
!isEmpty(this.address1) && !isEmpty(this.customer.address1) &&
!isEmpty(this.city) && !isEmpty(this.customer.city) &&
!isEmpty(this.zipCode) !isEmpty(this.customer.zipCode)
); );
}, },
countryOptionsWithDefault() { countryOptionsWithDefault() {
...@@ -142,12 +121,19 @@ export default { ...@@ -142,12 +121,19 @@ export default {
...this.states, ...this.states,
]; ];
}, },
selectedStateName() {
if (!this.customer.state || !this.states) {
return '';
}
return this.states.find((state) => state.id === this.customer.state).name;
},
}, },
methods: { methods: {
updateState(payload) { updateState(payload) {
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: UPDATE_STATE, mutation: updateStateMutation,
variables: { variables: {
input: payload, input: payload,
}, },
...@@ -173,14 +159,19 @@ export default { ...@@ -173,14 +159,19 @@ export default {
</script> </script>
<template> <template>
<step <step
v-if="!$apollo.loading" v-if="!$apollo.loading.customer"
:step-id="$options.stepId" :step-id="$options.stepId"
:title="$options.i18n.stepTitle" :title="$options.i18n.stepTitle"
:is-valid="isValid" :is-valid="isValid"
:next-step-button-text="$options.i18n.nextStepButtonText" :next-step-button-text="$options.i18n.nextStepButtonText"
> >
<template #body> <template #body>
<gl-form-group :label="$options.i18n.countryLabel" label-size="sm" class="mb-3"> <gl-form-group
v-if="!$apollo.loading.countries"
:label="$options.i18n.countryLabel"
label-size="sm"
class="mb-3"
>
<gl-form-select <gl-form-select
v-model="countryModel" v-model="countryModel"
v-autofocusonshow v-autofocusonshow
...@@ -207,9 +198,13 @@ export default { ...@@ -207,9 +198,13 @@ export default {
<gl-form-input v-model="cityModel" type="text" data-qa-selector="city" /> <gl-form-input v-model="cityModel" type="text" data-qa-selector="city" />
</gl-form-group> </gl-form-group>
<div class="combined d-flex"> <div class="combined d-flex">
<gl-form-group :label="$options.i18n.stateLabel" label-size="sm" class="mr-3 w-50"> <gl-form-group
v-if="!$apollo.loading.states && states"
:label="$options.i18n.stateLabel"
label-size="sm"
class="mr-3 w-50"
>
<gl-form-select <gl-form-select
v-if="states"
v-model="countryStateModel" v-model="countryStateModel"
:options="stateOptionsWithDefault" :options="stateOptionsWithDefault"
value-field="id" value-field="id"
...@@ -223,9 +218,11 @@ export default { ...@@ -223,9 +218,11 @@ export default {
</div> </div>
</template> </template>
<template #summary> <template #summary>
<div class="js-summary-line-1">{{ address1 }}</div> <div class="js-summary-line-1">{{ customer.address1 }}</div>
<div class="js-summary-line-2">{{ address2 }}</div> <div class="js-summary-line-2">{{ customer.address2 }}</div>
<div class="js-summary-line-3">{{ city }}, {{ country }} {{ state }} {{ zipCode }}</div> <div class="js-summary-line-3">
{{ customer.city }}, {{ customer.country }} {{ selectedStateName }} {{ customer.zipCode }}
</div>
</template> </template>
</step> </step>
</template> </template>
...@@ -3,7 +3,7 @@ import { merge } from 'lodash'; ...@@ -3,7 +3,7 @@ import { merge } from 'lodash';
import Api from 'ee/api'; import Api from 'ee/api';
import * as SubscriptionsApi from 'ee/api/subscriptions_api'; import * as SubscriptionsApi from 'ee/api/subscriptions_api';
import { ERROR_FETCHING_COUNTRIES, ERROR_FETCHING_STATES } from 'ee/subscriptions/constants'; import { ERROR_FETCHING_COUNTRIES, ERROR_FETCHING_STATES } from 'ee/subscriptions/constants';
import STATE_QUERY from 'ee/subscriptions/graphql/queries/state.query.graphql'; import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql';
import createFlash from '~/flash'; import createFlash from '~/flash';
// NOTE: These resolvers are temporary and will be removed in the future. // NOTE: These resolvers are temporary and will be removed in the future.
...@@ -38,13 +38,13 @@ export const resolvers = { ...@@ -38,13 +38,13 @@ export const resolvers = {
return SubscriptionsApi.createSubscription(groupId, customer, subscription); return SubscriptionsApi.createSubscription(groupId, customer, subscription);
}, },
updateState: (_, { input }, { cache }) => { updateState: (_, { input }, { cache }) => {
const oldState = cache.readQuery({ query: STATE_QUERY }); const oldState = cache.readQuery({ query: stateQuery });
const state = produce(oldState, (draftState) => { const state = produce(oldState, (draftState) => {
merge(draftState, input); merge(draftState, input);
}); });
cache.writeQuery({ query: STATE_QUERY, data: state }); cache.writeQuery({ query: stateQuery, data: state });
}, },
}, },
}; };
...@@ -4,7 +4,7 @@ import VueApollo from 'vue-apollo'; ...@@ -4,7 +4,7 @@ import VueApollo from 'vue-apollo';
import BillingAddress from 'ee/subscriptions/buy_minutes/components/checkout/billing_address.vue'; import BillingAddress from 'ee/subscriptions/buy_minutes/components/checkout/billing_address.vue';
import { resolvers } from 'ee/subscriptions/buy_minutes/graphql/resolvers'; import { resolvers } from 'ee/subscriptions/buy_minutes/graphql/resolvers';
import { STEPS } from 'ee/subscriptions/constants'; import { STEPS } from 'ee/subscriptions/constants';
import STATE_QUERY from 'ee/subscriptions/graphql/queries/state.query.graphql'; import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql';
import Step from 'ee/vue_shared/purchase_flow/components/step.vue'; import Step from 'ee/vue_shared/purchase_flow/components/step.vue';
import { stateData as initialStateData } from 'ee_jest/subscriptions/buy_minutes/mock_data'; import { stateData as initialStateData } from 'ee_jest/subscriptions/buy_minutes/mock_data';
import { createMockApolloProvider } from 'ee_jest/vue_shared/purchase_flow/spec_helper'; import { createMockApolloProvider } from 'ee_jest/vue_shared/purchase_flow/spec_helper';
...@@ -18,7 +18,11 @@ describe('Billing Address', () => { ...@@ -18,7 +18,11 @@ describe('Billing Address', () => {
const apolloResolvers = { const apolloResolvers = {
Query: { Query: {
countries: jest.fn().mockResolvedValue([{ id: 'NL', name: 'Netherlands' }]), countries: jest.fn().mockResolvedValue([
{ id: 'NL', name: 'Netherlands' },
{ id: 'US', name: 'United States of America' },
]),
states: jest.fn().mockResolvedValue([{ id: 'CA', name: 'California' }]),
}, },
}; };
...@@ -28,7 +32,7 @@ describe('Billing Address', () => { ...@@ -28,7 +32,7 @@ describe('Billing Address', () => {
...apolloResolvers, ...apolloResolvers,
}); });
apolloProvider.clients.defaultClient.cache.writeQuery({ apolloProvider.clients.defaultClient.cache.writeQuery({
query: STATE_QUERY, query: stateQuery,
data: merge({}, initialStateData, apolloLocalState), data: merge({}, initialStateData, apolloLocalState),
}); });
...@@ -125,15 +129,15 @@ describe('Billing Address', () => { ...@@ -125,15 +129,15 @@ describe('Billing Address', () => {
}); });
it('should show the entered address line 1', () => { it('should show the entered address line 1', () => {
expect(wrapper.find('.js-summary-line-1').text()).toEqual('address line 1'); expect(wrapper.find('.js-summary-line-1').text()).toBe('address line 1');
}); });
it('should show the entered address line 2', () => { it('should show the entered address line 2', () => {
expect(wrapper.find('.js-summary-line-2').text()).toEqual('address line 2'); expect(wrapper.find('.js-summary-line-2').text()).toBe('address line 2');
}); });
it('should show the entered address city, state and zip code', () => { it('should show the entered address city, state and zip code', () => {
expect(wrapper.find('.js-summary-line-3').text()).toEqual('city, US CA zip'); expect(wrapper.find('.js-summary-line-3').text()).toBe('city, US California zip');
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment