Commit fa55b7e7 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Preselect plan on mount

parent 394d1a47
<script> <script>
import updateState from 'ee/subscriptions/graphql/mutations/update_state.mutation.graphql';
import { GENERAL_ERROR_MESSAGE } from 'ee/vue_shared/purchase_flow/constants';
import createFlash from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import AddonPurchaseDetails from './checkout/addon_purchase_details.vue'; import AddonPurchaseDetails from './checkout/addon_purchase_details.vue';
import BillingAddress from './checkout/billing_address.vue'; import BillingAddress from './checkout/billing_address.vue';
...@@ -13,6 +16,23 @@ export default { ...@@ -13,6 +16,23 @@ export default {
required: true, required: true,
}, },
}, },
mounted() {
this.updateSelectedPlanId(this.plan.id);
},
methods: {
updateSelectedPlanId(planId) {
this.$apollo
.mutate({
mutation: updateState,
variables: {
input: { selectedPlanId: planId },
},
})
.catch((error) => {
createFlash({ message: GENERAL_ERROR_MESSAGE, error, captureError: true });
});
},
},
i18n: { i18n: {
checkout: s__('Checkout|Checkout'), checkout: s__('Checkout|Checkout'),
}, },
......
...@@ -31,21 +31,8 @@ export default { ...@@ -31,21 +31,8 @@ export default {
confirmOrderParams: { confirmOrderParams: {
query: stateQuery, query: stateQuery,
update(data) { update(data) {
const { customer } = data;
return { return {
setup_for_company: data.isSetupForCompany,
selected_group: data.subscription.namespaceId, selected_group: data.subscription.namespaceId,
new_user: data.isNewUser,
customer: {
country: customer.country,
address_1: customer.address1,
address_2: customer.address2,
city: customer.city,
state: customer.state,
zip_code: customer.zipCode,
company: customer.company,
},
subscription: { subscription: {
plan_id: data.selectedPlanId, plan_id: data.selectedPlanId,
payment_method_id: data.paymentMethod.id, payment_method_id: data.paymentMethod.id,
......
...@@ -11,7 +11,7 @@ function arrayToGraphqlArray(arr, typename) { ...@@ -11,7 +11,7 @@ function arrayToGraphqlArray(arr, typename) {
} }
export function writeInitialDataToApolloCache(apolloProvider, dataset) { export function writeInitialDataToApolloCache(apolloProvider, dataset) {
const { groupData, namespaceId, planId = null } = dataset; const { groupData, namespaceId } = dataset;
// eslint-disable-next-line @gitlab/require-i18n-strings // eslint-disable-next-line @gitlab/require-i18n-strings
const namespaces = arrayToGraphqlArray(JSON.parse(groupData), 'Namespace'); const namespaces = arrayToGraphqlArray(JSON.parse(groupData), 'Namespace');
...@@ -21,7 +21,7 @@ export function writeInitialDataToApolloCache(apolloProvider, dataset) { ...@@ -21,7 +21,7 @@ export function writeInitialDataToApolloCache(apolloProvider, dataset) {
isNewUser: false, isNewUser: false,
fullName: null, fullName: null,
isSetupForCompany: false, isSetupForCompany: false,
selectedPlanId: planId, selectedPlanId: null,
namespaces, namespaces,
subscription: { subscription: {
quantity: 1, quantity: 1,
......
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