Commit 1c49d292 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'fix-confetti-popup-on-back-button' into 'master'

Stop confetti popup from opening on browser back button

See merge request gitlab-org/gitlab!80423
parents cea40926 b0260a7f
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
import { GlProgressBar, GlSprintf, GlAlert } from '@gitlab/ui'; import { GlProgressBar, GlSprintf, GlAlert } from '@gitlab/ui';
import eventHub from '~/invite_members/event_hub'; import eventHub from '~/invite_members/event_hub';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { ACTION_LABELS, ACTION_SECTIONS } from '../constants'; import { getCookie, removeCookie, parseBoolean } from '~/lib/utils/common_utils';
import { ACTION_LABELS, ACTION_SECTIONS, INVITE_MODAL_OPEN_COOKIE } from '../constants';
import LearnGitlabSectionCard from './learn_gitlab_section_card.vue'; import LearnGitlabSectionCard from './learn_gitlab_section_card.vue';
export default { export default {
...@@ -26,7 +27,7 @@ export default { ...@@ -26,7 +27,7 @@ export default {
required: true, required: true,
type: Object, type: Object,
}, },
inviteMembersOpen: { inviteMembers: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -53,7 +54,7 @@ export default { ...@@ -53,7 +54,7 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.inviteMembersOpen) { if (this.inviteMembers && this.getCookieForInviteMembers()) {
this.openInviteMembersModal('celebrate'); this.openInviteMembersModal('celebrate');
} }
...@@ -63,6 +64,13 @@ export default { ...@@ -63,6 +64,13 @@ export default {
eventHub.$off('showSuccessfulInvitationsAlert', this.handleShowSuccessfulInvitationsAlert); eventHub.$off('showSuccessfulInvitationsAlert', this.handleShowSuccessfulInvitationsAlert);
}, },
methods: { methods: {
getCookieForInviteMembers() {
const value = parseBoolean(getCookie(INVITE_MODAL_OPEN_COOKIE));
removeCookie(INVITE_MODAL_OPEN_COOKIE);
return value;
},
openInviteMembersModal(mode) { openInviteMembersModal(mode) {
eventHub.$emit('openModal', { mode, inviteeType: 'members', source: 'learn-gitlab' }); eventHub.$emit('openModal', { mode, inviteeType: 'members', source: 'learn-gitlab' });
}, },
......
...@@ -95,3 +95,5 @@ export const ACTION_SECTIONS = { ...@@ -95,3 +95,5 @@ export const ACTION_SECTIONS = {
), ),
}, },
}; };
export const INVITE_MODAL_OPEN_COOKIE = 'confetti_post_signup';
import Vue from 'vue'; import Vue from 'vue';
import initInviteMembersModal from '~/invite_members/init_invite_members_modal'; import initInviteMembersModal from '~/invite_members/init_invite_members_modal';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
import LearnGitlab from '../components/learn_gitlab.vue'; import LearnGitlab from '../components/learn_gitlab.vue';
function initLearnGitlab() { function initLearnGitlab() {
...@@ -13,13 +13,13 @@ function initLearnGitlab() { ...@@ -13,13 +13,13 @@ function initLearnGitlab() {
const actions = convertObjectPropsToCamelCase(JSON.parse(el.dataset.actions)); const actions = convertObjectPropsToCamelCase(JSON.parse(el.dataset.actions));
const sections = convertObjectPropsToCamelCase(JSON.parse(el.dataset.sections)); const sections = convertObjectPropsToCamelCase(JSON.parse(el.dataset.sections));
const project = convertObjectPropsToCamelCase(JSON.parse(el.dataset.project)); const project = convertObjectPropsToCamelCase(JSON.parse(el.dataset.project));
const { inviteMembersOpen } = el.dataset; const { inviteMembers } = el.dataset;
return new Vue({ return new Vue({
el, el,
render(createElement) { render(createElement) {
return createElement(LearnGitlab, { return createElement(LearnGitlab, {
props: { actions, sections, project, inviteMembersOpen }, props: { actions, sections, project, inviteMembers: parseBoolean(inviteMembers) },
}); });
}, },
}); });
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
- page_title _("Learn GitLab") - page_title _("Learn GitLab")
- add_page_specific_style 'page_bundles/learn_gitlab' - add_page_specific_style 'page_bundles/learn_gitlab'
- data = learn_gitlab_data(@project) - data = learn_gitlab_data(@project)
- invite_members_open = session.delete(:confetti_post_signup)
= render 'projects/invite_members_modal', project: @project = render 'projects/invite_members_modal', project: @project
...@@ -10,4 +9,4 @@ ...@@ -10,4 +9,4 @@
- e.control do - e.control do
#js-learn-gitlab-app{ data: data } #js-learn-gitlab-app{ data: data }
- e.candidate do - e.candidate do
#js-learn-gitlab-app{ data: data.merge(invite_members_open: invite_members_open) } #js-learn-gitlab-app{ data: data.merge(invite_members: 'true') }
...@@ -41,7 +41,7 @@ module EE ...@@ -41,7 +41,7 @@ module EE
project = ::Project.find(params[:project_id]) project = ::Project.find(params[:project_id])
return access_denied! unless can?(current_user, :owner_access, project) return access_denied! unless can?(current_user, :owner_access, project)
session[:confetti_post_signup] = true cookies[:confetti_post_signup] = true
render locals: { project: project } render locals: { project: project }
end end
......
...@@ -42,7 +42,7 @@ RSpec.describe Registrations::WelcomeController do ...@@ -42,7 +42,7 @@ RSpec.describe Registrations::WelcomeController do
it 'sets the correct session key' do it 'sets the correct session key' do
continuous_onboarding_getting_started continuous_onboarding_getting_started
expect(session[:confetti_post_signup]).to eq(true) expect(cookies[:confetti_post_signup]).to eq('true')
end end
end end
......
import { GlProgressBar, GlAlert } from '@gitlab/ui'; import { GlProgressBar, GlAlert } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Cookies from 'js-cookie';
import LearnGitlab from '~/pages/projects/learn_gitlab/components/learn_gitlab.vue'; import LearnGitlab from '~/pages/projects/learn_gitlab/components/learn_gitlab.vue';
import eventHub from '~/invite_members/event_hub'; import eventHub from '~/invite_members/event_hub';
import { INVITE_MODAL_OPEN_COOKIE } from '~/pages/projects/learn_gitlab/constants';
import { testActions, testSections, testProject } from './mock_data'; import { testActions, testSections, testProject } from './mock_data';
describe('Learn GitLab', () => { describe('Learn GitLab', () => {
let wrapper; let wrapper;
let sidebar; let sidebar;
let inviteMembersOpen = false; let inviteMembers = false;
const createWrapper = () => { const createWrapper = () => {
wrapper = mount(LearnGitlab, { wrapper = mount(LearnGitlab, {
...@@ -15,7 +17,7 @@ describe('Learn GitLab', () => { ...@@ -15,7 +17,7 @@ describe('Learn GitLab', () => {
actions: testActions, actions: testActions,
sections: testSections, sections: testSections,
project: testProject, project: testProject,
inviteMembersOpen, inviteMembers,
}, },
}); });
}; };
...@@ -36,7 +38,7 @@ describe('Learn GitLab', () => { ...@@ -36,7 +38,7 @@ describe('Learn GitLab', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
inviteMembersOpen = false; inviteMembers = false;
sidebar.remove(); sidebar.remove();
}); });
...@@ -59,13 +61,20 @@ describe('Learn GitLab', () => { ...@@ -59,13 +61,20 @@ describe('Learn GitLab', () => {
describe('Invite Members Modal', () => { describe('Invite Members Modal', () => {
let spy; let spy;
let cookieSpy;
beforeEach(() => { beforeEach(() => {
spy = jest.spyOn(eventHub, '$emit'); spy = jest.spyOn(eventHub, '$emit');
cookieSpy = jest.spyOn(Cookies, 'remove');
});
afterEach(() => {
Cookies.remove(INVITE_MODAL_OPEN_COOKIE);
}); });
it('emits openModal', () => { it('emits openModal', () => {
inviteMembersOpen = true; inviteMembers = true;
Cookies.set(INVITE_MODAL_OPEN_COOKIE, true);
createWrapper(); createWrapper();
...@@ -74,9 +83,19 @@ describe('Learn GitLab', () => { ...@@ -74,9 +83,19 @@ describe('Learn GitLab', () => {
inviteeType: 'members', inviteeType: 'members',
source: 'learn-gitlab', source: 'learn-gitlab',
}); });
expect(cookieSpy).toHaveBeenCalledWith(INVITE_MODAL_OPEN_COOKIE);
});
it('does not emit openModal when cookie is not set', () => {
inviteMembers = true;
createWrapper();
expect(spy).not.toHaveBeenCalled();
expect(cookieSpy).toHaveBeenCalledWith(INVITE_MODAL_OPEN_COOKIE);
}); });
it('does not emit openModal', () => { it('does not emit openModal when inviteMembers is false', () => {
createWrapper(); createWrapper();
expect(spy).not.toHaveBeenCalled(); expect(spy).not.toHaveBeenCalled();
......
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