Skip to content

Commit

Permalink
fix sign latest agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 13, 2024
1 parent 2fa7846 commit 7430839
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 170 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"type-check": "tsc --build tsconfig.json"
},
"dependencies": {
"codeforlife": "github:ocadotechnology/codeforlife-package-javascript#v2.3.2"
"codeforlife": "github:ocadotechnology/codeforlife-package-javascript#contributor-frontend-4"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
Expand Down
9 changes: 4 additions & 5 deletions src/api/agreementSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import api from "."
export type AgreementSignature = Model<
number,
{
contributor: number
agreement_id: string
signed_at: Date
}
Expand All @@ -29,23 +28,23 @@ const agreementSignatureUrls = modelUrls(

export type RetrieveAgreementSignatureResult = RetrieveResult<
AgreementSignature,
"contributor" | "agreement_id" | "signed_at"
"agreement_id" | "signed_at"
>
export type RetrieveAgreementSignatureArg = RetrieveArg<AgreementSignature>

export type ListAgreementSignaturesResult = ListResult<
AgreementSignature,
"contributor" | "agreement_id" | "signed_at"
"agreement_id" | "signed_at"
>
export type ListAgreementSignaturesArg = ListArg

export type CreateAgreementSignatureResult = CreateResult<
AgreementSignature,
"contributor" | "agreement_id" | "signed_at"
"agreement_id" | "signed_at"
>
export type CreateAgreementSignatureArg = CreateArg<
AgreementSignature,
"contributor" | "agreement_id" | "signed_at"
"agreement_id" | "signed_at"
>

export type CheckSignedLatestAgreementSignatureResult = {
Expand Down
48 changes: 27 additions & 21 deletions src/pages/agreementSignatures/AgreementSignatures.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
import * as pages from "codeforlife/components/page"
import { type FC } from "react"
import { type FC, useEffect } from "react"
import { handleResultState } from "codeforlife/utils/api"

import { type SessionMetadata, useSession } from "../../app/hooks"
import AgreementSignatureTable from "./AgreementSignatureTable"
import SignLatestAgreementForm from "./SignLatestAgreementForm"
import { useCheckSignedLatestAgreementSignatureQuery } from "../../api/agreementSignature"
import { useLazyCheckSignedLatestAgreementSignatureQuery } from "../../api/agreementSignature"
import { useSession } from "../../app/hooks"

const SignLatestAgreementFormSection: FC<SessionMetadata> = ({
contributor_id,
}) =>
handleResultState(
useCheckSignedLatestAgreementSignatureQuery(null),
({ latest_commit_id, is_signed }) =>
is_signed ? (
<></>
) : (
<pages.Section>
<SignLatestAgreementForm
contributor={contributor_id}
agreementId={latest_commit_id}
/>
</pages.Section>
),
const SignLatestAgreementFormSection: FC = () => {
const [checkSignedLatestAgreementSignature, result] =
useLazyCheckSignedLatestAgreementSignatureQuery()

useEffect(() => {
void checkSignedLatestAgreementSignature(null)
}, [checkSignedLatestAgreementSignature])

return handleResultState(result, ({ latest_commit_id, is_signed }) =>
is_signed ? (
<></>
) : (
<pages.Section>
<SignLatestAgreementForm
agreementId={latest_commit_id}
onSign={() => {
void checkSignedLatestAgreementSignature(null)
}}
/>
</pages.Section>
),
)
}

export interface AgreementSignaturesProps {}

const AgreementSignatures: FC<AgreementSignaturesProps> = () =>
useSession(metadata => (
useSession(() => (
<pages.Page>
<pages.Banner header="Agreement Signatures" />
<SignLatestAgreementFormSection {...metadata} />
<SignLatestAgreementFormSection />
<pages.Section>
<AgreementSignatureTable />
</pages.Section>
Expand Down
9 changes: 5 additions & 4 deletions src/pages/agreementSignatures/SignLatestAgreementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import { PriorityHigh as PriorityHighIcon } from "@mui/icons-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"]
onSign: () => void
}

const SignLatestAgreementForm: FC<SignLatestAgreementFormProps> = ({
contributor,
agreementId,
onSign,
}) => {
const [createAgreementSignature] = useCreateAgreementSignatureMutation()

Expand All @@ -34,13 +33,15 @@ const SignLatestAgreementForm: FC<SignLatestAgreementFormProps> = ({
<forms.Form
initialValues={{
read_and_understood: false,
contributor,
agreement_id: agreementId,
// Placeholder for when the agreement was signed at.
signed_at: new Date(),
}}
onSubmit={submitForm(createAgreementSignature, {
exclude: ["read_and_understood"],
// Set the actual date-time the agreement was signed at.
clean: values => ({ ...values, signed_at: new Date() }),
then: onSign,
})}
>
<Stack direction={{ xs: "column", sm: "row" }} gap={2}>
Expand Down
Loading

0 comments on commit 7430839

Please sign in to comment.