Skip to content

Commit

Permalink
refactor: apply PR requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Sep 20, 2024
1 parent 68f3e7d commit fd51a38
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
21 changes: 12 additions & 9 deletions src/Authorization/PreventGuestWrapper.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import BuildIcon from '@/icons/BuildIcon.js';

import PreventGuestWrapper from './PreventGuestWrapper.js';

const meta: Meta<typeof PreventGuestWrapper> = {
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: (
<div data-testid='content'>
<BuildIcon />
Expand All @@ -21,13 +24,13 @@ const meta: Meta<typeof PreventGuestWrapper> = {
</div>
),
},
};
} satisfies Meta<typeof PreventGuestWrapper>;

export default meta;

type Story = StoryObj<typeof PreventGuestWrapper>;
type Story = StoryObj<typeof meta>;

export const Guest: Story = {
export const Guest = {
args: {
currentAccount: { type: AccountType.Guest } as CompleteGuest,
},
Expand All @@ -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,
},
Expand All @@ -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',
},
Expand All @@ -63,4 +66,4 @@ export const ShowError: Story = {
await expect(canvas.getByText(args.errorText)).toBeVisible();
}
},
};
} satisfies Story;
14 changes: 7 additions & 7 deletions src/Authorization/PreventGuestWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ import { ReactNode } from 'react';
import { AccountType, CurrentAccount } from '@graasp/sdk';

type Props = {
buttonText?: string;
buttonText: string;
children?: ReactNode;
currentAccount?: CurrentAccount | null;
/**
* Component to display on error.
* 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 = <ClipboardPen />,
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 (
<Stack height='100%' justifyContent='center' alignItems='center'>
Expand Down
3 changes: 2 additions & 1 deletion src/Authorization/SignedInWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion src/itemLogin/ItemLoginAuthorization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<ItemLoginScreen
itemId={itemId}
Expand Down

0 comments on commit fd51a38

Please sign in to comment.