generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
589 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import AlertApiUnavailable from 'components/AlertApiUnavailable'; | ||
import { LoadingContent } from 'components/Loading'; | ||
import { Button } from 'design-system-react'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { FILING_STATUS_CODE_FILING_EXISTS } from 'utils/constants'; | ||
import useCreateFiling from 'utils/useCreateFiling'; | ||
|
||
export function FilingCreate(): JSX.Element | null | undefined { | ||
const { lei, year } = useParams(); | ||
const navigate = useNavigate(); | ||
|
||
const { isLoading, error, data: filing } = useCreateFiling(lei, year); | ||
|
||
/** Missing required param, cannot continue */ | ||
if (!lei || !year) { | ||
navigate('/filing'); | ||
return null; | ||
} | ||
|
||
if (isLoading) return <LoadingContent message='Loading filing data...' />; | ||
|
||
/** Filing exists */ | ||
if ( | ||
filing ?? | ||
Number(error?.response?.status) === FILING_STATUS_CODE_FILING_EXISTS | ||
) { | ||
// Note: React was complaining about setState during render. This setTimeout seems to resolve the issue. | ||
setTimeout(() => navigate(`/filing/${year}/${lei}/upload`), 0); | ||
return <LoadingContent message='Loading filing data...' />; | ||
} | ||
|
||
const onReturnToFiling = (): void => navigate('/filing'); | ||
|
||
if (error) | ||
return ( | ||
<div className='u-mt45 u-mb45 mx-3'> | ||
<AlertApiUnavailable | ||
message={`Unable to create a ${year} Filing for ${lei}`} | ||
/> | ||
<div> | ||
<Button | ||
label='Return to Filing overview' | ||
onClick={onReturnToFiling} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default FilingCreate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.