generated from ocadotechnology/codeforlife-template-frontend
-
Notifications
You must be signed in to change notification settings - Fork 8
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
15 changed files
with
232 additions
and
288 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# Service. | ||
VITE_SERVICE_NAME=contributor | ||
|
||
# Links. | ||
VITE_LINK_GH_LOGIN=https://github.com/login/oauth/authorize?client_id=Ov23liBErSabQFqROeMg | ||
VITE_LINK_GH_CONTRIBUTING=https://github.com/ocadotechnology/codeforlife-workspace/blob/{commitId}/CONTRIBUTING.md |
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
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
71 changes: 0 additions & 71 deletions
71
src/pages/agreementSignatureDetails/AgreementSignatureDetails.tsx
This file was deleted.
Oops, something went wrong.
61 changes: 19 additions & 42 deletions
61
src/pages/agreementSignatureList/AgreementSignatureList.tsx
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 |
---|---|---|
@@ -1,55 +1,32 @@ | ||
import * as pages from "codeforlife/components/page" | ||
import { Stack, Typography } from "@mui/material" | ||
import { type FC } from "react" | ||
import { LinkIconButton } from "codeforlife/components/router" | ||
import { TablePagination } from "codeforlife/components" | ||
import { generatePath } from "react-router" | ||
import { paths } from "../../routes" | ||
import { useLazyListAgreementSignaturesQuery } from "../../api/agreementSignature" | ||
|
||
import AgreementSignatureTable from "./AgreementSignatureTable" | ||
import SignLatestAgreementForm from "./SignLatestAgreementForm" | ||
import { useSession } from "../../app/hooks" | ||
|
||
export interface AgreementSignatureListProps {} | ||
|
||
const AgreementSignatureList: FC<AgreementSignatureListProps> = () => { | ||
return ( | ||
const signedLatestAgreement = false // TODO: call endpoint | ||
const latestAgreementId = "" // TODO: call endpoint | ||
|
||
return useSession(({ contributor_id }) => ( | ||
<pages.Page> | ||
<pages.Banner header="Agreement Signatures" /> | ||
{!signedLatestAgreement && ( | ||
<pages.Section> | ||
<SignLatestAgreementForm | ||
contributor={contributor_id} | ||
agreementId={latestAgreementId} | ||
/> | ||
</pages.Section> | ||
)} | ||
<pages.Section> | ||
<Typography variant="h1">Agreement Signature List</Typography> | ||
<TablePagination | ||
useLazyListQuery={useLazyListAgreementSignaturesQuery} | ||
preferCacheValue | ||
> | ||
{agreementSignatures => ( | ||
<> | ||
<Stack direction="row" gap={5}> | ||
<Typography fontWeight="bold">ID</Typography> | ||
<Typography fontWeight="bold"> | ||
Contributor (Agreement ID) | ||
</Typography> | ||
</Stack> | ||
{agreementSignatures.map(agreementSignature => ( | ||
<Stack direction="row" key={agreementSignature.id} gap={5}> | ||
<Typography fontWeight="bold"> | ||
{agreementSignature.id} | ||
</Typography> | ||
<Typography> | ||
{agreementSignature.contributor} ( | ||
{agreementSignature.agreement_id}) | ||
</Typography> | ||
<LinkIconButton | ||
to={generatePath(paths.agreementSignatures.id._, { | ||
id: agreementSignature.id, | ||
})} | ||
> | ||
<Typography>View</Typography> | ||
</LinkIconButton> | ||
</Stack> | ||
))} | ||
</> | ||
)} | ||
</TablePagination> | ||
<AgreementSignatureTable /> | ||
</pages.Section> | ||
</pages.Page> | ||
) | ||
)) | ||
} | ||
|
||
export default AgreementSignatureList |
64 changes: 64 additions & 0 deletions
64
src/pages/agreementSignatureList/AgreementSignatureTable.tsx
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,64 @@ | ||
import { | ||
Paper, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableHead, | ||
TableRow, | ||
} from "@mui/material" | ||
import { type FC } from "react" | ||
import { LinkIconButton } from "codeforlife/components/router" | ||
import { OpenInNew as OpenInNewIcon } from "@mui/icons-material" | ||
import { TablePagination } from "codeforlife/components" | ||
|
||
import { LINK_GH_CONTRIBUTING } from "../../app/env" | ||
import { useLazyListAgreementSignaturesQuery } from "../../api/agreementSignature" | ||
|
||
export interface AgreementSignatureTableProps {} | ||
|
||
const AgreementSignatureTable: FC<AgreementSignatureTableProps> = () => { | ||
return ( | ||
<TablePagination | ||
useLazyListQuery={useLazyListAgreementSignaturesQuery} | ||
preferCacheValue | ||
> | ||
{agreementSignatures => ( | ||
<TableContainer component={Paper}> | ||
<Table stickyHeader> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>ID</TableCell> | ||
<TableCell>Signed at</TableCell> | ||
<TableCell>Link</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{agreementSignatures.map(agreementSignature => ( | ||
<TableRow key={agreementSignature.id}> | ||
<TableCell>{agreementSignature.agreement_id}</TableCell> | ||
<TableCell> | ||
{agreementSignature.signed_at.toLocaleString()} | ||
</TableCell> | ||
<TableCell> | ||
<LinkIconButton | ||
to={LINK_GH_CONTRIBUTING.replace( | ||
"{commitId}", | ||
agreementSignature.agreement_id, | ||
)} | ||
target="_blank" | ||
> | ||
<OpenInNewIcon /> | ||
</LinkIconButton> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
)} | ||
</TablePagination> | ||
) | ||
} | ||
|
||
export default AgreementSignatureTable |
66 changes: 66 additions & 0 deletions
66
src/pages/agreementSignatureList/SignLatestAgreementForm.tsx
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,66 @@ | ||
import * as forms from "codeforlife/components/form" | ||
import { type FC } from "react" | ||
import { Link } from "codeforlife/components/router" | ||
import { PriorityHigh as PriorityHighIcon } from "@mui/icons-material" | ||
import { Typography } from "@mui/material" | ||
import { submitForm } from "codeforlife/utils/form" | ||
|
||
import { type AgreementSignature } from "../../api/agreementSignature" | ||
import { type Contributor } from "../../api/contributor" | ||
import { LINK_GH_CONTRIBUTING } from "../../app/env" | ||
import { useCreateAgreementSignatureMutation } from "../../api/agreementSignature" | ||
|
||
export interface SignLatestAgreementFormProps { | ||
contributor: Contributor["id"] | ||
agreementId: AgreementSignature["agreement_id"] | ||
} | ||
|
||
const SignLatestAgreementForm: FC<SignLatestAgreementFormProps> = ({ | ||
contributor, | ||
agreementId, | ||
}) => { | ||
const [createAgreementSignature] = useCreateAgreementSignatureMutation() | ||
|
||
return ( | ||
<> | ||
<Typography color="error.main"> | ||
You have not signed the latest agreement! | ||
</Typography> | ||
<forms.Form | ||
initialValues={{ | ||
read_and_understood: false, | ||
contributor, | ||
agreement_id: agreementId, | ||
signed_at: new Date(), | ||
}} | ||
onSubmit={submitForm(createAgreementSignature, { | ||
exclude: ["read_and_understood"], | ||
clean: values => ({ ...values, signed_at: new Date() }), | ||
})} | ||
> | ||
<forms.CheckboxField | ||
name="read_and_understood" | ||
required | ||
formControlLabelProps={{ | ||
label: ( | ||
<> | ||
I have read and understood the{" "} | ||
<Link | ||
to={LINK_GH_CONTRIBUTING.replace("{commitId}", agreementId)} | ||
> | ||
agreement | ||
</Link> | ||
. | ||
</> | ||
), | ||
}} | ||
/> | ||
<forms.SubmitButton className="alert" startIcon={<PriorityHighIcon />}> | ||
Sign agreement | ||
</forms.SubmitButton> | ||
</forms.Form> | ||
</> | ||
) | ||
} | ||
|
||
export default SignLatestAgreementForm |
Oops, something went wrong.