Commit ea39dfb3 authored by Alex Buijs's avatar Alex Buijs

Move progress bar and make configurable

Make the registration progress bar more
reusable friendly.
parent 903ab1ab
<script> <script>
import { s__ } from '~/locale';
export default { export default {
props: { props: {
step: { steps: {
type: Number, type: Array,
required: true,
},
currentStep: {
type: String,
required: true, required: true,
}, },
}, },
computed: {
currentStepIndex() {
return this.steps.indexOf(this.currentStep);
},
},
methods: { methods: {
classObject(stepNumber) { classObject(stepIndex) {
return { return {
phase: true, phase: true,
bold: true, bold: true,
center: true, center: true,
finished: this.step > stepNumber, finished: this.currentStepIndex > stepIndex,
current: this.step === stepNumber, current: this.currentStepIndex === stepIndex,
}; };
}, },
}, },
i18n: {
yourProfile: s__('Checkout|1. Your profile'),
checkout: s__('Checkout|2. Checkout'),
yourGroup: s__('Checkout|3. Your GitLab group'),
},
}; };
</script> </script>
<template> <template>
<div class="bar d-flex"> <div class="bar d-flex">
<div v-for="(value, name, index) in $options.i18n" :key="name" :class="classObject(index + 1)"> <div v-for="(step, index) in steps" :key="index" :class="classObject(index)">
{{ value }} {{ index + 1 }}. {{ step }}
</div> </div>
</div> </div>
</template> </template>
import { s__ } from '~/locale';
export const STEPS = {
yourProfile: s__('Registration|Your profile'),
checkout: s__('Registration|Checkout'),
yourGroup: s__('Registration|Your GitLab group'),
yourProject: s__('Registration|Your first project'),
};
export const SUBSCRIPTON_FLOW_STEPS = [STEPS.yourProfile, STEPS.checkout, STEPS.yourGroup];
import Vue from 'vue'; import Vue from 'vue';
import { PROGRESS_STEPS } from 'ee/subscriptions/new/constants'; import { STEPS } from '../constants';
import ProgressBar from 'ee/subscriptions/new/components/checkout/progress_bar.vue'; import ProgressBar from '../components/progress_bar.vue';
export default () => { export default () => {
const progressBarEl = document.getElementById('progress-bar'); const el = document.getElementById('progress-bar');
if (!el) return null;
const steps = [STEPS.yourProfile, STEPS.yourGroup, STEPS.yourProject];
return new Vue({ return new Vue({
el: progressBarEl, el,
render(createElement) { render(createElement) {
return createElement(ProgressBar, { props: { step: PROGRESS_STEPS.editProfile } }); return createElement(ProgressBar, {
props: { steps, currentStep: STEPS.yourProfile },
});
}, },
}); });
}; };
import Vue from 'vue'; import Vue from 'vue';
import { PROGRESS_STEPS } from 'ee/subscriptions/new/constants'; import { STEPS, SUBSCRIPTON_FLOW_STEPS } from 'ee/registrations/constants';
import ProgressBar from 'ee/subscriptions/new/components/checkout/progress_bar.vue'; import ProgressBar from 'ee/registrations/components/progress_bar.vue';
export default () => { export default () => {
const progressBarEl = document.getElementById('progress-bar'); const el = document.getElementById('progress-bar');
if (!el) return null;
return new Vue({ return new Vue({
el: progressBarEl, el,
render(createElement) { render(createElement) {
return createElement(ProgressBar, { props: { step: PROGRESS_STEPS.editGroup } }); return createElement(ProgressBar, {
props: { steps: SUBSCRIPTON_FLOW_STEPS, currentStep: STEPS.yourGroup },
});
}, },
}); });
}; };
<script> <script>
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { PROGRESS_STEPS } from '../constants'; import { STEPS, SUBSCRIPTON_FLOW_STEPS } from 'ee/registrations/constants';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import ProgressBar from './checkout/progress_bar.vue'; import ProgressBar from 'ee/registrations/components/progress_bar.vue';
import SubscriptionDetails from './checkout/subscription_details.vue'; import SubscriptionDetails from './checkout/subscription_details.vue';
import BillingAddress from './checkout/billing_address.vue'; import BillingAddress from './checkout/billing_address.vue';
import PaymentMethod from './checkout/payment_method.vue'; import PaymentMethod from './checkout/payment_method.vue';
...@@ -10,11 +10,8 @@ import ConfirmOrder from './checkout/confirm_order.vue'; ...@@ -10,11 +10,8 @@ import ConfirmOrder from './checkout/confirm_order.vue';
export default { export default {
components: { ProgressBar, SubscriptionDetails, BillingAddress, PaymentMethod, ConfirmOrder }, components: { ProgressBar, SubscriptionDetails, BillingAddress, PaymentMethod, ConfirmOrder },
data() { steps: SUBSCRIPTON_FLOW_STEPS,
return { currentStep: STEPS.checkout,
step: PROGRESS_STEPS.checkout,
};
},
computed: { computed: {
...mapState(['isNewUser']), ...mapState(['isNewUser']),
}, },
...@@ -26,7 +23,7 @@ export default { ...@@ -26,7 +23,7 @@ export default {
<template> <template>
<div class="checkout d-flex flex-column justify-content-between w-100"> <div class="checkout d-flex flex-column justify-content-between w-100">
<div class="full-width"> <div class="full-width">
<progress-bar v-if="isNewUser" :step="step" /> <progress-bar v-if="isNewUser" :steps="$options.steps" :current-step="$options.currentStep" />
<div class="flash-container"></div> <div class="flash-container"></div>
<h2 class="mt-4 mb-3 mb-lg-5">{{ $options.i18n.checkout }}</h2> <h2 class="mt-4 mb-3 mb-lg-5">{{ $options.i18n.checkout }}</h2>
<subscription-details /> <subscription-details />
......
...@@ -11,12 +11,6 @@ export const ZUORA_IFRAME_OVERRIDE_PARAMS = { ...@@ -11,12 +11,6 @@ export const ZUORA_IFRAME_OVERRIDE_PARAMS = {
retainValues: 'true', retainValues: 'true',
}; };
export const PROGRESS_STEPS = {
editProfile: 1,
checkout: 2,
editGroup: 3,
};
export const TAX_RATE = 0; export const TAX_RATE = 0;
export const NEW_GROUP = 'new_group'; export const NEW_GROUP = 'new_group';
---
title: Move registrations progress bar to a generic place and make it configurable
merge_request: 31484
author:
type: changed
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Component from 'ee/subscriptions/new/components/checkout/progress_bar.vue'; import Component from 'ee/registrations/components/progress_bar.vue';
describe('Progress Bar', () => { describe('Progress Bar', () => {
let wrapper; let wrapper;
...@@ -14,7 +14,7 @@ describe('Progress Bar', () => { ...@@ -14,7 +14,7 @@ describe('Progress Bar', () => {
const secondStep = () => wrapper.find('.bar div:nth-child(2)'); const secondStep = () => wrapper.find('.bar div:nth-child(2)');
beforeEach(() => { beforeEach(() => {
createComponent({ step: 2 }); createComponent({ currentStep: 'b', steps: ['a', 'b'] });
}); });
afterEach(() => { afterEach(() => {
......
...@@ -2,7 +2,7 @@ import Vuex from 'vuex'; ...@@ -2,7 +2,7 @@ import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import createStore from 'ee/subscriptions/new/store'; import createStore from 'ee/subscriptions/new/store';
import Component from 'ee/subscriptions/new/components/checkout.vue'; import Component from 'ee/subscriptions/new/components/checkout.vue';
import ProgressBar from 'ee/subscriptions/new/components/checkout/progress_bar.vue'; import ProgressBar from 'ee/registrations/components/progress_bar.vue';
describe('Checkout', () => { describe('Checkout', () => {
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -37,4 +37,22 @@ describe('Checkout', () => { ...@@ -37,4 +37,22 @@ describe('Checkout', () => {
expect(findProgressBar().exists()).toBe(visible); expect(findProgressBar().exists()).toBe(visible);
}); });
}); });
describe('passing the correct options to the progress bar component', () => {
beforeEach(() => {
store.state.isNewUser = true;
});
it('passes the steps', () => {
expect(findProgressBar().props('steps')).toEqual([
'Your profile',
'Checkout',
'Your GitLab group',
]);
});
it('passes the current step', () => {
expect(findProgressBar().props('currentStep')).toEqual('Checkout');
});
});
}); });
...@@ -3836,15 +3836,6 @@ msgstr "" ...@@ -3836,15 +3836,6 @@ msgstr ""
msgid "Checkout|(x%{numberOfUsers})" msgid "Checkout|(x%{numberOfUsers})"
msgstr "" msgstr ""
msgid "Checkout|1. Your profile"
msgstr ""
msgid "Checkout|2. Checkout"
msgstr ""
msgid "Checkout|3. Your GitLab group"
msgstr ""
msgid "Checkout|Billing address" msgid "Checkout|Billing address"
msgstr "" msgstr ""
...@@ -17232,6 +17223,18 @@ msgstr "" ...@@ -17232,6 +17223,18 @@ msgstr ""
msgid "Registration" msgid "Registration"
msgstr "" msgstr ""
msgid "Registration|Checkout"
msgstr ""
msgid "Registration|Your GitLab group"
msgstr ""
msgid "Registration|Your first project"
msgstr ""
msgid "Registration|Your profile"
msgstr ""
msgid "Related Deployed Jobs" msgid "Related Deployed Jobs"
msgstr "" msgstr ""
......
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