Skip to content

Commit e0bf95b

Browse files
authored
fix: show request access on forbidden only (#1081)
* fix: show request access on forbidden only * refactor: fix type
1 parent b3787ca commit e0bf95b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/itemLogin/ItemLoginWrapper.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import { expect } from '@storybook/test';
33
import { within } from '@storybook/testing-library';
4+
import { StatusCodes } from 'http-status-codes';
45
import { v4 } from 'uuid';
56

67
import {
@@ -32,7 +33,7 @@ const meta = {
3233
args: {
3334
signIn: () => {},
3435
itemId: item.id,
35-
36+
itemErrorStatusCode: null,
3637
children: <Card alt='card' name='card' />,
3738
},
3839
} satisfies Meta<typeof ItemLoginWrapper>;
@@ -93,6 +94,7 @@ export const RequestAccess = {
9394
args: {
9495
currentAccount,
9596
itemId: v4(),
97+
itemErrorStatusCode: StatusCodes.FORBIDDEN,
9698
requestAccessContent: <div data-testId='request'>Request Access</div>,
9799
},
98100
play: async ({ canvasElement }) => {

src/itemLogin/ItemLoginWrapper.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { StatusCodes } from 'http-status-codes';
2+
13
import { ReactElement, ReactNode } from 'react';
24

35
import {
@@ -15,6 +17,7 @@ import ItemLoginScreen, { SignInPropertiesType } from './ItemLoginScreen.js';
1517
export type ItemLoginAuthorizationProps = {
1618
signIn: (args: { itemId: string } & SignInPropertiesType) => void;
1719
itemId: UUID;
20+
itemErrorStatusCode: number | null;
1821
currentAccount?: CurrentAccount | null;
1922
item?: DiscriminatedItem;
2023
itemLoginSchemaType?: ItemLoginSchemaType;
@@ -31,6 +34,7 @@ export type ItemLoginAuthorizationProps = {
3134
const ItemLoginAuthorization = ({
3235
currentAccount,
3336
item,
37+
itemErrorStatusCode,
3438
itemLoginSchemaType,
3539
itemId,
3640
signIn,
@@ -61,8 +65,13 @@ const ItemLoginAuthorization = ({
6165
return enrollContent ?? forbiddenContent;
6266
}
6367

64-
// user is logged in and item login disabled - request access
65-
return requestAccessContent ?? forbiddenContent;
68+
// user is logged in and item login disabled
69+
// cannot access to item - request access
70+
if (itemErrorStatusCode === StatusCodes.FORBIDDEN) {
71+
return requestAccessContent ?? forbiddenContent;
72+
}
73+
// any other error return forbidden message
74+
return forbiddenContent;
6675
} else {
6776
return forbiddenContent;
6877
}

0 commit comments

Comments
 (0)