Commit fa55b7e7 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Preselect plan on mount

parent 394d1a47
<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 AddonPurchaseDetails from './checkout/addon_purchase_details.vue';
import BillingAddress from './checkout/billing_address.vue';
......@@ -13,6 +16,23 @@ export default {
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: {
checkout: s__('Checkout|Checkout'),
},
......
......@@ -31,21 +31,8 @@ export default {
confirmOrderParams: {
query: stateQuery,
update(data) {
const { customer } = data;
return {
setup_for_company: data.isSetupForCompany,
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: {
plan_id: data.selectedPlanId,
payment_method_id: data.paymentMethod.id,
......
......@@ -11,7 +11,7 @@ function arrayToGraphqlArray(arr, typename) {
}
export function writeInitialDataToApolloCache(apolloProvider, dataset) {
const { groupData, namespaceId, planId = null } = dataset;
const { groupData, namespaceId } = dataset;
// eslint-disable-next-line @gitlab/require-i18n-strings
const namespaces = arrayToGraphqlArray(JSON.parse(groupData), 'Namespace');
......@@ -21,7 +21,7 @@ export function writeInitialDataToApolloCache(apolloProvider, dataset) {
isNewUser: false,
fullName: null,
isSetupForCompany: false,
selectedPlanId: planId,
selectedPlanId: null,
namespaces,
subscription: {
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