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

Fix the summary section

parent 5d53332b
<script> <script>
import { GlIcon, GlCollapse, GlCollapseToggleDirective } from '@gitlab/ui'; import { GlIcon, GlCollapse, GlCollapseToggleDirective } from '@gitlab/ui';
import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql'; import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql';
import { TAX_RATE, NEW_GROUP } from 'ee/subscriptions/new/constants'; import { TAX_RATE } from 'ee/subscriptions/new/constants';
import formattingMixins from 'ee/subscriptions/new/formatting_mixins'; import formattingMixins from 'ee/subscriptions/new/formatting_mixins';
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import SummaryDetails from './order_summary/summary_details.vue'; import SummaryDetails from './order_summary/summary_details.vue';
...@@ -17,8 +17,8 @@ export default { ...@@ -17,8 +17,8 @@ export default {
}, },
mixins: [formattingMixins], mixins: [formattingMixins],
props: { props: {
plans: { plan: {
type: Array, type: Object,
required: true, required: true,
}, },
}, },
...@@ -27,12 +27,8 @@ export default { ...@@ -27,12 +27,8 @@ export default {
query: stateQuery, query: stateQuery,
manual: true, manual: true,
result({ data }) { result({ data }) {
this.subscription = data.subscription;
this.namespaces = data.namespaces; this.namespaces = data.namespaces;
this.isSetupForCompany = data.isSetupForCompany; this.subscription = data.subscription;
this.fullName = data.fullName;
this.customer = data.customer;
this.selectedPlanId = data.selectedPlanId;
}, },
}, },
}, },
...@@ -40,22 +36,16 @@ export default { ...@@ -40,22 +36,16 @@ export default {
return { return {
subscription: {}, subscription: {},
namespaces: [], namespaces: [],
isSetupForCompany: false,
isBottomSummaryVisible: false, isBottomSummaryVisible: false,
fullName: null,
customer: {},
selectedPlanId: null,
}; };
}, },
mounted() {},
computed: { computed: {
selectedPlan() {
return this.plans.find((plan) => plan.id === this.selectedPlanId);
},
selectedPlanPrice() { selectedPlanPrice() {
return this.selectedPlan.pricePerYear; return this.plan.pricePerYear;
}, },
selectedGroup() { selectedGroup() {
return this.namespaces.find((group) => group.id === this.subscription.namespaceId); return this.namespaces.find((group) => group.id === +this.subscription.namespaceId);
}, },
totalExVat() { totalExVat() {
return this.subscription.quantity * this.selectedPlanPrice; return this.subscription.quantity * this.selectedPlanPrice;
...@@ -66,46 +56,21 @@ export default { ...@@ -66,46 +56,21 @@ export default {
totalAmount() { totalAmount() {
return this.totalExVat + this.vat; return this.totalExVat + this.vat;
}, },
usersPresent() { quantityPresent() {
return this.subscription.quantity > 0; return this.subscription.quantity > 0;
}, },
isGroupSelected() { namespaceName() {
return this.subscription.namespaceId && this.subscription.namespaceId !== NEW_GROUP; return this.selectedGroup.name;
},
isSelectedGroupPresent() {
return (
this.isGroupSelected &&
this.namespaces.some((namespace) => namespace.id === this.subscription.namespaceId)
);
},
name() {
if (this.isSetupForCompany && this.customer.company) {
return this.customer.company;
}
if (this.isGroupSelected && this.isSelectedGroupPresent) {
return this.selectedGroup.name;
}
if (this.isSetupForCompany) {
return s__('Checkout|Your organization');
}
return this.fullName;
}, },
titleWithName() { titleWithName() {
return sprintf(this.$options.i18n.title, { name: this.name }); return sprintf(this.$options.i18n.title, { name: this.namespaceName });
}, },
isVisible() { isVisible() {
return ( return !this.$apollo.loading;
!this.$apollo.loading &&
(!this.isGroupSelected || this.isSelectedGroupPresent) &&
this.selectedPlan
);
}, },
}, },
i18n: { i18n: {
title: s__("Checkout|%{name}'s GitLab subscription"), title: s__("Checkout|%{name}'s CI minutes"),
}, },
taxRate: TAX_RATE, taxRate: TAX_RATE,
}; };
...@@ -123,18 +88,18 @@ export default { ...@@ -123,18 +88,18 @@ export default {
<gl-icon v-else name="chevron-right" /> <gl-icon v-else name="chevron-right" />
<div>{{ titleWithName }}</div> <div>{{ titleWithName }}</div>
</div> </div>
<div class="gl-ml-3">{{ formatAmount(totalAmount, usersPresent) }}</div> <div class="gl-ml-3">{{ formatAmount(totalAmount, quantityPresent) }}</div>
</h4> </h4>
</div> </div>
<gl-collapse id="summary-details" v-model="isBottomSummaryVisible"> <gl-collapse id="summary-details" v-model="isBottomSummaryVisible">
<summary-details <summary-details
:vat="vat" :vat="vat"
:total-ex-vat="totalExVat" :total-ex-vat="totalExVat"
:users-present="usersPresent" :quantity-present="quantityPresent"
:selected-plan-text="selectedPlan.name" :selected-plan-text="plan.name"
:selected-plan-price="selectedPlanPrice" :selected-plan-price="selectedPlanPrice"
:total-amount="totalAmount" :total-amount="totalAmount"
:number-of-users="subscription.quantity" :quantity="subscription.quantity"
:tax-rate="$options.taxRate" :tax-rate="$options.taxRate"
/> />
</gl-collapse> </gl-collapse>
...@@ -148,11 +113,11 @@ export default { ...@@ -148,11 +113,11 @@ export default {
<summary-details <summary-details
:vat="vat" :vat="vat"
:total-ex-vat="totalExVat" :total-ex-vat="totalExVat"
:users-present="usersPresent" :quantity-present="quantityPresent"
:selected-plan-text="selectedPlan.name" :selected-plan-text="plan.name"
:selected-plan-price="selectedPlanPrice" :selected-plan-price="selectedPlanPrice"
:total-amount="totalAmount" :total-amount="totalAmount"
:number-of-users="subscription.quantity" :quantity="subscription.quantity"
:tax-rate="$options.taxRate" :tax-rate="$options.taxRate"
/> />
</div> </div>
......
...@@ -13,10 +13,6 @@ export default { ...@@ -13,10 +13,6 @@ export default {
type: Number, type: Number,
required: true, required: true,
}, },
usersPresent: {
type: Boolean,
required: true,
},
selectedPlanText: { selectedPlanText: {
type: String, type: String,
required: true, required: true,
...@@ -29,7 +25,7 @@ export default { ...@@ -29,7 +25,7 @@ export default {
type: Number, type: Number,
required: true, required: true,
}, },
numberOfUsers: { quantity: {
type: Number, type: Number,
required: true, required: true,
}, },
...@@ -38,6 +34,10 @@ export default { ...@@ -38,6 +34,10 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
purchaseHasExpiration: {
type: Boolean,
required: false,
},
}, },
data() { data() {
return { return {
...@@ -51,8 +51,8 @@ export default { ...@@ -51,8 +51,8 @@ export default {
}, },
i18n: { i18n: {
selectedPlanText: s__('Checkout|%{selectedPlanText} plan'), selectedPlanText: s__('Checkout|%{selectedPlanText} plan'),
numberOfUsers: s__('Checkout|(x%{numberOfUsers})'), quantity: s__('Checkout|(x%{quantity})'),
pricePerUserPerYear: s__('Checkout|$%{selectedPlanPrice} per user per year'), pricePerUnitPerYear: s__('Checkout|$%{selectedPlanPrice} per pack per year'),
dates: s__('Checkout|%{startDate} - %{endDate}'), dates: s__('Checkout|%{startDate} - %{endDate}'),
subtotal: s__('Checkout|Subtotal'), subtotal: s__('Checkout|Subtotal'),
tax: s__('Checkout|Tax'), tax: s__('Checkout|Tax'),
...@@ -65,20 +65,20 @@ export default { ...@@ -65,20 +65,20 @@ export default {
<div class="d-flex justify-content-between bold gl-mt-3 gl-mb-3"> <div class="d-flex justify-content-between bold gl-mt-3 gl-mb-3">
<div class="js-selected-plan"> <div class="js-selected-plan">
{{ sprintf($options.i18n.selectedPlanText, { selectedPlanText }) }} {{ sprintf($options.i18n.selectedPlanText, { selectedPlanText }) }}
<span v-if="usersPresent" class="js-number-of-users">{{ <span v-if="quantity > 0" class="js-quantity">{{
sprintf($options.i18n.numberOfUsers, { numberOfUsers }) sprintf($options.i18n.quantity, { quantity })
}}</span> }}</span>
</div> </div>
<div class="js-amount">{{ formatAmount(totalExVat, usersPresent) }}</div> <div class="js-amount">{{ formatAmount(totalExVat, quantity > 0) }}</div>
</div> </div>
<div class="text-secondary js-per-user"> <div class="text-secondary js-per-unit">
{{ {{
sprintf($options.i18n.pricePerUserPerYear, { sprintf($options.i18n.pricePerUnitPerYear, {
selectedPlanPrice: selectedPlanPrice.toLocaleString(), selectedPlanPrice: selectedPlanPrice.toLocaleString(),
}) })
}} }}
</div> </div>
<div class="text-secondary js-dates"> <div v-if="purchaseHasExpiration" class="text-secondary js-dates">
{{ {{
sprintf($options.i18n.dates, { sprintf($options.i18n.dates, {
startDate: formatDate(startDate), startDate: formatDate(startDate),
...@@ -90,17 +90,17 @@ export default { ...@@ -90,17 +90,17 @@ export default {
<div class="border-bottom gl-mt-3 gl-mb-3"></div> <div class="border-bottom gl-mt-3 gl-mb-3"></div>
<div class="d-flex justify-content-between text-secondary"> <div class="d-flex justify-content-between text-secondary">
<div>{{ $options.i18n.subtotal }}</div> <div>{{ $options.i18n.subtotal }}</div>
<div class="js-total-ex-vat">{{ formatAmount(totalExVat, usersPresent) }}</div> <div class="js-total-ex-vat">{{ formatAmount(totalExVat, quantity > 0) }}</div>
</div> </div>
<div class="d-flex justify-content-between text-secondary"> <div class="d-flex justify-content-between text-secondary">
<div>{{ $options.i18n.tax }}</div> <div>{{ $options.i18n.tax }}</div>
<div class="js-vat">{{ formatAmount(vat, usersPresent) }}</div> <div class="js-vat">{{ formatAmount(vat, quantity > 0) }}</div>
</div> </div>
</div> </div>
<div class="border-bottom gl-mt-3 gl-mb-3"></div> <div class="border-bottom gl-mt-3 gl-mb-3"></div>
<div class="d-flex justify-content-between bold gl-font-lg"> <div class="d-flex justify-content-between bold gl-font-lg">
<div>{{ $options.i18n.total }}</div> <div>{{ $options.i18n.total }}</div>
<div class="js-total-amount">{{ formatAmount(totalAmount, usersPresent) }}</div> <div class="js-total-amount">{{ formatAmount(totalAmount, quantity > 0) }}</div>
</div> </div>
</div> </div>
</template> </template>
import { STEPS } from 'ee/subscriptions/constants'; import { STEPS } from 'ee/subscriptions/constants';
import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql'; import stateQuery from 'ee/subscriptions/graphql/queries/state.query.graphql';
import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
function arrayToGraphqlArray(arr, typename) { function arrayToGraphqlArray(arr, typename) {
return Array.from(arr, (item) => { return Array.from(arr, (item) => {
...@@ -11,23 +11,21 @@ function arrayToGraphqlArray(arr, typename) { ...@@ -11,23 +11,21 @@ function arrayToGraphqlArray(arr, typename) {
} }
export function writeInitialDataToApolloCache(apolloProvider, dataset) { export function writeInitialDataToApolloCache(apolloProvider, dataset) {
const { groupData, newUser, setupForCompany, fullName, planId = null } = dataset; const { groupData, namespaceId, planId = null } = 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');
const isNewUser = parseBoolean(newUser);
const isSetupForCompany = parseBoolean(setupForCompany) || !isNewUser;
apolloProvider.clients.defaultClient.cache.writeQuery({ apolloProvider.clients.defaultClient.cache.writeQuery({
query: stateQuery, query: stateQuery,
data: { data: {
isNewUser, isNewUser: false,
isSetupForCompany, fullName: null,
namespaces, isSetupForCompany: false,
fullName,
selectedPlanId: planId, selectedPlanId: planId,
namespaces,
subscription: { subscription: {
quantity: 1, quantity: 1,
namespaceId: null, namespaceId,
// eslint-disable-next-line @gitlab/require-i18n-strings // eslint-disable-next-line @gitlab/require-i18n-strings
__typename: 'Subscription', __typename: 'Subscription',
}, },
......
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