From ba71f519e4789a963ec362408d97a6b7df62d509 Mon Sep 17 00:00:00 2001 From: Hugo Lavernhe Date: Sat, 10 Aug 2024 16:13:34 +0200 Subject: [PATCH] Open `OnBoardingModal` for modals requiring a membership (#4859) * fix: replace modal * add case with wallet --- packages/ui/src/app/GlobalModals.tsx | 22 +++++++++++++------ .../modals/AnnounceCandidacyModal.test.tsx | 10 +++------ .../forum/modals/CreateThreadModal.test.tsx | 6 +---- .../modals/ApplyForRoleModal.test.tsx | 6 +---- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/packages/ui/src/app/GlobalModals.tsx b/packages/ui/src/app/GlobalModals.tsx index 148ac24c03..7ada2bea47 100644 --- a/packages/ui/src/app/GlobalModals.tsx +++ b/packages/ui/src/app/GlobalModals.tsx @@ -3,6 +3,7 @@ import React, { memo, ReactElement, useEffect, useMemo, useState } from 'react' import ReactDOM from 'react-dom' import styled from 'styled-components' +import { useMyAccounts } from '@/accounts/hooks/useMyAccounts' import { ClaimVestingModalCall } from '@/accounts/modals/ClaimVestingModal' import { ClaimVestingModal } from '@/accounts/modals/ClaimVestingModal/ClaimVestingModal' import { MoveFundsModal, MoveFundsModalCall } from '@/accounts/modals/MoveFundsModal' @@ -225,6 +226,7 @@ export const GlobalModals = () => { const { active: activeMember } = useMyMemberships() const { status } = useTransactionStatus() const Modal = useMemo(() => (modal && modal in modals ? memo(() => modals[modal as ModalNames]) : null), [modal]) + const { wallet } = useMyAccounts() const [container, setContainer] = useState(document.body) useEffect(() => { @@ -235,13 +237,19 @@ export const GlobalModals = () => { const potentialFallback = useGlobalModalHandler(currentModalMachine, hideModal) if (modal && !GUEST_ACCESSIBLE_MODALS.includes(modal as ModalNames) && !activeMember) { - showModal({ - modal: 'SwitchMember', - data: { - originalModalName: modal as ModalNames, - originalModalData: modalData, - }, - }) + if (wallet) { + showModal({ + modal: 'SwitchMember', + data: { + originalModalName: modal as ModalNames, + originalModalData: modalData, + }, + }) + } else { + showModal({ + modal: 'OnBoardingModal', + }) + } return null } diff --git a/packages/ui/test/council/modals/AnnounceCandidacyModal.test.tsx b/packages/ui/test/council/modals/AnnounceCandidacyModal.test.tsx index d990ea1c85..6daa3e7720 100644 --- a/packages/ui/test/council/modals/AnnounceCandidacyModal.test.tsx +++ b/packages/ui/test/council/modals/AnnounceCandidacyModal.test.tsx @@ -109,16 +109,12 @@ describe('UI: Announce Candidacy Modal', () => { renderModal() - const switchMemberModalCall = { - modal: 'SwitchMember', - data: { - originalModalName: 'AnnounceCandidateModal', - originalModalData: null, - }, + const onBoardingModalCall = { + modal: 'OnBoardingModal', } expect(showModal).toBeCalledTimes(1) - expect(showModal).toBeCalledWith({ ...switchMemberModalCall }) + expect(showModal).toBeCalledWith({ ...onBoardingModalCall }) }) it('Transaction fee', async () => { diff --git a/packages/ui/test/forum/modals/CreateThreadModal.test.tsx b/packages/ui/test/forum/modals/CreateThreadModal.test.tsx index 286562a419..f59dc32880 100644 --- a/packages/ui/test/forum/modals/CreateThreadModal.test.tsx +++ b/packages/ui/test/forum/modals/CreateThreadModal.test.tsx @@ -80,11 +80,7 @@ describe('CreateThreadModal', () => { useMyMemberships.active = undefined renderModal() expect(useModal.showModal).toBeCalledWith({ - modal: 'SwitchMember', - data: { - originalModalName: 'CreateThreadModal', - originalModalData: useModal.modalData, - }, + modal: 'OnBoardingModal', }) }) diff --git a/packages/ui/test/working-groups/modals/ApplyForRoleModal.test.tsx b/packages/ui/test/working-groups/modals/ApplyForRoleModal.test.tsx index 181a42621d..f412b6383e 100644 --- a/packages/ui/test/working-groups/modals/ApplyForRoleModal.test.tsx +++ b/packages/ui/test/working-groups/modals/ApplyForRoleModal.test.tsx @@ -135,11 +135,7 @@ describe('UI: ApplyForRoleModal', () => { await renderModal() expect(showModal).toBeCalledWith({ - modal: 'SwitchMember', - data: { - originalModalData: modalData, - originalModalName: 'ApplyForRoleModal', - }, + modal: 'OnBoardingModal', }) showModal.mockClear() })