Skip to content

Commit

Permalink
fix(Request): prevent application signed out when visiting Request page
Browse files Browse the repository at this point in the history
  • Loading branch information
duonglq-tsdv authored and heliocastro committed Dec 20, 2024
1 parent 41088df commit c1eb48b
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 292 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -411,64 +411,66 @@ export default function BulkDeclineModerationRequestModal({
}
}


if (status === 'unauthenticated') {
signOut()
} else {
return (
<>
<Modal
size='lg'
centered
show={show}
onHide={() => {
setShow(false)
setHasComment(false)
setStatusCheck(0)
setDisableAcceptMr(false)
setDisableDeclineMr(false)
}}
aria-labelledby={t('Accept Decline All Selected Moderation Requests')}
scrollable
return (
<>
<Modal
size='lg'
centered
show={show}
onHide={() => {
setShow(false)
setHasComment(false)
setStatusCheck(0)
setDisableAcceptMr(false)
setDisableDeclineMr(false)
}}
aria-labelledby={t('Accept Decline All Selected Moderation Requests')}
scrollable
>
<Modal.Header
style={{ backgroundColor: '#feefef', color: '#da1414' }}
closeButton
>
<Modal.Header style={{ backgroundColor: '#feefef',
color: '#da1414' }}
closeButton>
<Modal.Title id='delete-all-license-info-modal'>
<AiOutlineQuestionCircle />
{t('Accept Decline All Selected Moderation Requests')}
</Modal.Title>
</Modal.Header>
<Modal.Body>
<p className='my-3'>{t('Accept Decline All MRs')}</p>
<Form>
<Modal.Title id='delete-all-license-info-modal'>
<AiOutlineQuestionCircle />
{t('Accept Decline All Selected Moderation Requests')}
</Modal.Title>
</Modal.Header>
<Modal.Body>
<p className='my-3'>{t('Accept Decline All MRs')}</p>
<Form>
<Form.Group className='mb-3'>
<Form.Label className='mb-1'>
{t.rich('Your selected Moderation requests are')}
<div className='col-12 d-flex justify-content-center align-items-center'>
{loading == false ? (
<div style={{ paddingLeft: '0px' }}>
<Table columns={columns}
<Table
columns={columns}
data={tableData}
sort={false}
selector={true}
/>
</div>
) : (
<Spinner className='spinner' />
)
}
) : (
<Spinner className='spinner' />
)}
</div>
</Form.Label>
<br />
<Form.Label style={{ fontWeight: 'bold' }}>
{t('Please provide your comments')}{' '}
<span className='text-red' style={{ color: '#F7941E' }}>
<span
className='text-red'
style={{ color: '#F7941E' }}
>
*
</span>
</Form.Label>
<p className='subscriptionBox'
style={{textAlign: 'left'}}>
<p
className='subscriptionBox'
style={{ textAlign: 'left' }}
>
{t('Note for comments')}
</p>
<Form.Control
Expand All @@ -478,51 +480,55 @@ export default function BulkDeclineModerationRequestModal({
placeholder='Comment your message...'
onChange={handleUserComment}
required
/>
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer>
<button
className='btn btn-dark'
onClick={() => {
setShow(false)
setHasComment(false)
setStatusCheck(0)
setDisableAcceptMr(false)
setDisableDeclineMr(false)
}}
>
{(disableAcceptMr || disableDeclineMr) ? t('Close') : t('Cancel')}

</button>
<button
className='btn btn-danger'
onClick={async () => {
await handleBulkDeclineModerationRequests()
}}
disabled={!hasComment || disableDeclineMr}
>
{t('Bulk Decline Moderation Requests')}{' '}
{loading &&
<Spinner size='sm' className='ms-1 spinner' />
}
</button>
<button
className='btn btn-success'
onClick={async () => {
await handleBulkAcceptModerationRequests()
}}
disabled={!hasComment || disableAcceptMr}
>
{t('Bulk Accept Moderation Requests')}{' '}
{loading &&
<Spinner size='sm' className='ms-1 spinner' />
}
</button>
</Modal.Footer>
</Modal>
</>
)
}
/>
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer>
<button
className='btn btn-dark'
onClick={() => {
setShow(false)
setHasComment(false)
setStatusCheck(0)
setDisableAcceptMr(false)
setDisableDeclineMr(false)
}}
>
{disableAcceptMr || disableDeclineMr ? t('Close') : t('Cancel')}
</button>
<button
className='btn btn-danger'
onClick={async () => {
await handleBulkDeclineModerationRequests()
}}
disabled={!hasComment || disableDeclineMr}
>
{t('Bulk Decline Moderation Requests')}{' '}
{loading && (
<Spinner
size='sm'
className='ms-1 spinner'
/>
)}
</button>
<button
className='btn btn-success'
onClick={async () => {
await handleBulkAcceptModerationRequests()
}}
disabled={!hasComment || disableAcceptMr}
>
{t('Bulk Accept Moderation Requests')}{' '}
{loading && (
<Spinner
size='sm'
className='ms-1 spinner'
/>
)}
</button>
</Modal.Footer>
</Modal>
</>
)
}
38 changes: 17 additions & 21 deletions src/app/[locale]/requests/components/ClosedClearingRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,28 +244,24 @@ function ClosedClearingRequest() {
})
}, [fetchData])

if (status === 'unauthenticated') {
signOut()
} else {
return (
<div className='row mb-4'>
<div className='col-12 d-flex justify-content-center align-items-center'>
{loading == false ? (
<div style={{ paddingLeft: '0px' }}>
<Table
columns={columns}
data={tableData}
sort={false}
selector={true}
/>
</div>
) : (
<Spinner className='spinner' />
)}
</div>
return (
<div className='row mb-4'>
<div className='col-12 d-flex justify-content-center align-items-center'>
{loading == false ? (
<div style={{ paddingLeft: '0px' }}>
<Table
columns={columns}
data={tableData}
sort={false}
selector={true}
/>
</div>
) : (
<Spinner className='spinner' />
)}
</div>
)
}
</div>
)
}

export default ClosedClearingRequest
38 changes: 17 additions & 21 deletions src/app/[locale]/requests/components/ClosedModerationRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,24 @@ function ClosedModerationRequest() {
},
]

if (status === 'unauthenticated') {
signOut()
} else {
return (
<div className='row mb-4'>
<div className='col-12 d-flex justify-content-center align-items-center'>
{loading == false ? (
<div style={{ paddingLeft: '0px' }}>
<Table
columns={columns}
data={tableData}
sort={false}
selector={true}
/>
</div>
) : (
<Spinner className='spinner' />
)}
</div>
return (
<div className='row mb-4'>
<div className='col-12 d-flex justify-content-center align-items-center'>
{loading == false ? (
<div style={{ paddingLeft: '0px' }}>
<Table
columns={columns}
data={tableData}
sort={false}
selector={true}
/>
</div>
) : (
<Spinner className='spinner' />
)}
</div>
)
}
</div>
)
}

export default ClosedModerationRequest
51 changes: 22 additions & 29 deletions src/app/[locale]/requests/components/OpenClearingRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -42,16 +42,14 @@ interface ProjectData {

function LicenseClearing(licenseClearing: LicenseClearing) {
const [lcData, setLcData] = useState<LicenseClearingData | null>(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`,
Expand All @@ -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'] ? (
<div className='text-center'>{`${lcData['Release Count']}`}</div>
) : null}
{licenseClearing.clearingProgress ?? false ? (
<div className='text-center'>
{`${lcData['Approved Count']}/${lcData['Release Count']}`}
</div>
) : null}
</>
) : (
<div className='col-12 text-center'>
<Spinner className='spinner' />
</div>
)}
</>
)
}
return (
<>
{lcData ? (
<>
{(licenseClearing.openReleases ?? false) && lcData['Release Count'] ? (
<div className='text-center'>{`${lcData['Release Count']}`}</div>
) : null}
{licenseClearing.clearingProgress ?? false ? (
<div className='text-center'>{`${lcData['Approved Count']}/${lcData['Release Count']}`}</div>
) : null}
</>
) : (
<div className='col-12 text-center'>
<Spinner className='spinner' />
</div>
)}
</>
)
}

function OpenClearingRequest() {
Expand All @@ -124,6 +116,7 @@ function OpenClearingRequest() {
}, [])

useEffect(() => {
if(status !== 'authenticated') return
setLoading(true)
void fetchData('clearingrequests').then((clearingRequests: EmbeddedClearingRequest | undefined) => {
const filteredClearingRequests = clearingRequests?._embedded['sw360:clearingRequests'].filter(
Expand Down
Loading

0 comments on commit c1eb48b

Please sign in to comment.