From fd51a3888ae36f701a7c3753514be88a4b892d4c Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 20 Sep 2024 10:36:20 +0200 Subject: [PATCH] refactor: apply PR requested changes --- .../PreventGuestWrapper.stories.tsx | 21 +++++++++++-------- src/Authorization/PreventGuestWrapper.tsx | 14 ++++++------- src/Authorization/SignedInWrapper.tsx | 3 ++- src/itemLogin/ItemLoginAuthorization.tsx | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Authorization/PreventGuestWrapper.stories.tsx b/src/Authorization/PreventGuestWrapper.stories.tsx index 281a519c..8eb64889 100644 --- a/src/Authorization/PreventGuestWrapper.stories.tsx +++ b/src/Authorization/PreventGuestWrapper.stories.tsx @@ -7,12 +7,15 @@ import BuildIcon from '@/icons/BuildIcon.js'; import PreventGuestWrapper from './PreventGuestWrapper.js'; -const meta: Meta = { +const meta = { title: 'Actions/PreventGuestWrapper', component: PreventGuestWrapper, argTypes: {}, args: { + buttonText: 'Log out and Create a Graasp account', + errorText: 'An error occured.', + text: 'You are currently using Graasp with a guest account. In order to use all features of Graasp, you have to log out and create a Graasp account.', children: (
@@ -21,13 +24,13 @@ const meta: Meta = {
), }, -}; +} satisfies Meta; export default meta; -type Story = StoryObj; +type Story = StoryObj; -export const Guest: Story = { +export const Guest = { args: { currentAccount: { type: AccountType.Guest } as CompleteGuest, }, @@ -37,9 +40,9 @@ export const Guest: Story = { // should see message await expect(canvas.getByRole('alert')).toBeVisible(); }, -}; +} satisfies Story; -export const Individual: Story = { +export const Individual = { args: { currentAccount: { id: 'member', name: 'member' } as CompleteMember, }, @@ -49,9 +52,9 @@ export const Individual: Story = { // should see content await expect(canvas.getByTestId('content')).toBeVisible(); }, -}; +} satisfies Story; -export const ShowError: Story = { +export const ShowError = { args: { errorText: 'error text', }, @@ -63,4 +66,4 @@ export const ShowError: Story = { await expect(canvas.getByText(args.errorText)).toBeVisible(); } }, -}; +} satisfies Story; diff --git a/src/Authorization/PreventGuestWrapper.tsx b/src/Authorization/PreventGuestWrapper.tsx index ac17da8c..4a785285 100644 --- a/src/Authorization/PreventGuestWrapper.tsx +++ b/src/Authorization/PreventGuestWrapper.tsx @@ -14,7 +14,7 @@ import { ReactNode } from 'react'; import { AccountType, CurrentAccount } from '@graasp/sdk'; type Props = { - buttonText?: string; + buttonText: string; children?: ReactNode; currentAccount?: CurrentAccount | null; /** @@ -22,26 +22,26 @@ type Props = { * Overrides errorText */ error?: JSX.Element; - errorText?: string; + errorText: string; id?: string; onButtonClick?: () => void; startIcon?: JSX.Element; - text?: string | JSX.Element; + text: string | JSX.Element; }; const PreventGuestWrapper = ({ - buttonText = 'Log out and Create a Graasp account', + buttonText, children, currentAccount, error, id, onButtonClick, startIcon = , - errorText = 'An error occured.', - text = 'You are currently using Graasp with a guest account. In order to use all features of Graasp, you have to log out and create a Graasp account.', + errorText, + text, }: Props): ReactNode => { if (currentAccount) { - // guest - should not have access to home + // guest - should not have access to children if (currentAccount.type === AccountType.Guest) { return ( diff --git a/src/Authorization/SignedInWrapper.tsx b/src/Authorization/SignedInWrapper.tsx index bed23353..a33f79e5 100644 --- a/src/Authorization/SignedInWrapper.tsx +++ b/src/Authorization/SignedInWrapper.tsx @@ -19,7 +19,8 @@ const SignedInWrapper = ({ }: SignedInWrapperProps): SignedInWrapperProps['children'] => { const redirectToSignIn = (): void => { if (!redirectionLink) { - return console.debug('No link has been set for redirection'); + console.debug('No link has been set for redirection'); + return; } redirect(window, redirectionLink); }; diff --git a/src/itemLogin/ItemLoginAuthorization.tsx b/src/itemLogin/ItemLoginAuthorization.tsx index 1cd20dc2..e3631b99 100644 --- a/src/itemLogin/ItemLoginAuthorization.tsx +++ b/src/itemLogin/ItemLoginAuthorization.tsx @@ -50,7 +50,7 @@ const ItemLoginAuthorization = ({ } // signed out but can sign in with item login - if ((!currentAccount || !currentAccount.id) && itemLoginSchemaType) { + if (!currentAccount?.id && itemLoginSchemaType) { return (