From a0b258124e6f9b32f7c6a6ba21f195ea76eb247a Mon Sep 17 00:00:00 2001 From: duonglq-tsdv Date: Wed, 11 Dec 2024 14:32:15 +0700 Subject: [PATCH] fix(Request): prevent application signed out when visiting Request page --- .../[id]/components/ClearingRequestDetail.tsx | 256 +++++++++--------- .../BulkDeclineModerationRequestModal.tsx | 176 ++++++------ .../components/ClosedClearingRequest.tsx | 38 ++- .../components/ClosedModerationRequest.tsx | 38 ++- .../components/OpenClearingRequest.tsx | 50 ++-- .../components/OpenModerationRequest.tsx | 4 +- .../[locale]/requests/components/Requests.tsx | 10 +- 7 files changed, 280 insertions(+), 292 deletions(-) diff --git a/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingRequestDetail.tsx b/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingRequestDetail.tsx index 07d3ef33..c28472d8 100644 --- a/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingRequestDetail.tsx +++ b/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingRequestDetail.tsx @@ -95,154 +95,150 @@ function ClearingRequestDetail({ clearingRequestId }: { clearingRequestId: strin setOpenCardIndex((prevIndex) => (prevIndex === index ? -1 : index)) } - if (status === 'unauthenticated') { - signOut() - } else { - return ( - <> - -
- + return ( + <> + +
+ + - - - {clearingRequestData && `${clearingRequestData.id}`} + + {clearingRequestData && `${clearingRequestData.id}`} + + + + + + + + - - - - - - - - - - -
toggleCollapse(0)} - style={{ cursor: 'pointer', padding: '0' }} - > - + +
toggleCollapse(0)} + style={{ cursor: 'pointer', padding: '0' }} + > + + + +
+ +
+ +
+
+
- - -
- -
- -
-
- -
-
- -
+
+
- -
- - - - - -
toggleCollapse(1)} - style={{ cursor: 'pointer', padding: '0' }} - > - + +
+ +
+
+ + +
toggleCollapse(1)} + style={{ cursor: 'pointer', padding: '0' }} + > + + - -
- -
- -
-
- {openCardIndex === 1 && ( - - )} -
+ {t('Clearing Request Comments') + + ' ' + + `(${clearingRequestData?.comments?.length})`} + + +
+ +
+ +
+
+ {openCardIndex === 1 && ( + + )}
- -
- - - - - - -
- - ) - } +
+
+
+
+ + + + + +
+ + ) } export default ClearingRequestDetail diff --git a/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx b/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx index afc5fcb7..e4a9cd96 100644 --- a/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx +++ b/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx @@ -411,64 +411,66 @@ export default function BulkDeclineModerationRequestModal({ } } - - if (status === 'unauthenticated') { - signOut() - } else { - return ( - <> - { - setShow(false) - setHasComment(false) - setStatusCheck(0) - setDisableAcceptMr(false) - setDisableDeclineMr(false) - }} - aria-labelledby={t('Accept Decline All Selected Moderation Requests')} - scrollable + return ( + <> + { + setShow(false) + setHasComment(false) + setStatusCheck(0) + setDisableAcceptMr(false) + setDisableDeclineMr(false) + }} + aria-labelledby={t('Accept Decline All Selected Moderation Requests')} + scrollable + > + - - - - {t('Accept Decline All Selected Moderation Requests')} - - - -

{t('Accept Decline All MRs')}

-
+ + + {t('Accept Decline All Selected Moderation Requests')} + + + +

{t('Accept Decline All MRs')}

+ {t.rich('Your selected Moderation requests are')}
{loading == false ? (
- - ) : ( - - ) - } + ) : ( + + )}
{t('Please provide your comments')}{' '} - + * -

+

{t('Note for comments')}

- - - - - - - - - - - ) - } + /> + + + + + + + + + + + ) } diff --git a/src/app/[locale]/requests/components/ClosedClearingRequest.tsx b/src/app/[locale]/requests/components/ClosedClearingRequest.tsx index ca8b1e76..90ef20ba 100644 --- a/src/app/[locale]/requests/components/ClosedClearingRequest.tsx +++ b/src/app/[locale]/requests/components/ClosedClearingRequest.tsx @@ -244,28 +244,24 @@ function ClosedClearingRequest() { }) }, [fetchData]) - if (status === 'unauthenticated') { - signOut() - } else { - return ( -
-
- {loading == false ? ( -
-
- - ) : ( - - )} - + return ( +
+
+ {loading == false ? ( +
+
+ + ) : ( + + )} - ) - } + + ) } export default ClosedClearingRequest diff --git a/src/app/[locale]/requests/components/ClosedModerationRequest.tsx b/src/app/[locale]/requests/components/ClosedModerationRequest.tsx index 962a4ac4..bf0c82c5 100644 --- a/src/app/[locale]/requests/components/ClosedModerationRequest.tsx +++ b/src/app/[locale]/requests/components/ClosedModerationRequest.tsx @@ -140,28 +140,24 @@ function ClosedModerationRequest() { }, ] - if (status === 'unauthenticated') { - signOut() - } else { - return ( -
-
- {loading == false ? ( -
-
- - ) : ( - - )} - + return ( +
+
+ {loading == false ? ( +
+
+ + ) : ( + + )} - ) - } + + ) } export default ClosedModerationRequest diff --git a/src/app/[locale]/requests/components/OpenClearingRequest.tsx b/src/app/[locale]/requests/components/OpenClearingRequest.tsx index f6b3805e..83be2712 100644 --- a/src/app/[locale]/requests/components/OpenClearingRequest.tsx +++ b/src/app/[locale]/requests/components/OpenClearingRequest.tsx @@ -11,7 +11,7 @@ import { ClearingRequest, Embedded, HttpStatus } from '@/object-types' import { ApiUtils, CommonUtils } from '@/utils/index' -import { signOut, useSession } from 'next-auth/react' +import { getSession, signOut, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { Table, _ } from 'next-sw360' import Link from 'next/link' @@ -42,16 +42,14 @@ interface ProjectData { function LicenseClearing(licenseClearing: LicenseClearing) { const [lcData, setLcData] = useState(null) - const { data: session, status } = useSession() useEffect(() => { const controller = new AbortController() const signal = controller.signal ;(async () => { try { - if (!session) { - return signOut() - } + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)) return signOut() const response = await ApiUtils.GET( `projects/${licenseClearing.projectId}/licenseClearingCount`, @@ -75,30 +73,24 @@ function LicenseClearing(licenseClearing: LicenseClearing) { return () => controller.abort() }, [licenseClearing.projectId]) - if (status === 'unauthenticated') { - signOut() - } else { - return ( - <> - {lcData ? ( - <> - {(licenseClearing.openReleases ?? false) && lcData['Release Count'] ? ( -
{`${lcData['Release Count']}`}
- ) : null} - {licenseClearing.clearingProgress ?? false ? ( -
- {`${lcData['Approved Count']}/${lcData['Release Count']}`} -
- ) : null} - - ) : ( -
- -
- )} - - ) - } + return ( + <> + {lcData ? ( + <> + {(licenseClearing.openReleases ?? false) && lcData['Release Count'] ? ( +
{`${lcData['Release Count']}`}
+ ) : null} + {licenseClearing.clearingProgress ?? false ? ( +
{`${lcData['Approved Count']}/${lcData['Release Count']}`}
+ ) : null} + + ) : ( +
+ +
+ )} + + ) } function OpenClearingRequest() { diff --git a/src/app/[locale]/requests/components/OpenModerationRequest.tsx b/src/app/[locale]/requests/components/OpenModerationRequest.tsx index ef1f10fb..cbdbc760 100644 --- a/src/app/[locale]/requests/components/OpenModerationRequest.tsx +++ b/src/app/[locale]/requests/components/OpenModerationRequest.tsx @@ -55,13 +55,13 @@ function OpenModerationRequest() { const fetchData = useCallback( async (url: string) => { - if (CommonUtils.isNullOrUndefined(session)) return signOut() + if (CommonUtils.isNullOrUndefined(session)) return const response = await ApiUtils.GET(url, session.user.access_token) if (response.status == HttpStatus.OK) { const data = (await response.json()) as EmbeddedModerationRequest return data } else if (response.status == HttpStatus.UNAUTHORIZED) { - return signOut() + return } else { notFound() } diff --git a/src/app/[locale]/requests/components/Requests.tsx b/src/app/[locale]/requests/components/Requests.tsx index 8860b33d..9ba6cfd0 100644 --- a/src/app/[locale]/requests/components/Requests.tsx +++ b/src/app/[locale]/requests/components/Requests.tsx @@ -141,13 +141,13 @@ function Requests() { const fetchData = useCallback( async (url: string) => { if (CommonUtils.isNullOrUndefined(session)) - return signOut() + return const response = await ApiUtils.GET(url, session.user.access_token) if (response.status == HttpStatus.OK) { const data = await response.json() return data } else if (response.status == HttpStatus.UNAUTHORIZED) { - return signOut() + return } else { notFound() } @@ -156,7 +156,8 @@ function Requests() { useEffect(() => { void fetchData('moderationrequest') - .then((moderationRequests: EmbeddedModerationRequest) => { + .then((moderationRequests: EmbeddedModerationRequest | undefined) => { + if(!moderationRequests) return let openMRCount = 0 let closedMRCount = 0 moderationRequests['_embedded']['sw360:moderationRequests'] @@ -174,7 +175,8 @@ function Requests() { setClosedModerationRequestCount(closedMRCount) }) void fetchData('clearingrequests') - .then((clearingRequests: EmbeddedClearingRequest) => { + .then((clearingRequests: EmbeddedClearingRequest | undefined) => { + if(!clearingRequests) return let openCRCount = 0 let closedCRCount = 0 clearingRequests['_embedded']['sw360:clearingRequests']