From 6429fdf5cd7b6b46c89eea9c7dfe4a205448c5c6 Mon Sep 17 00:00:00 2001 From: shadrach Date: Mon, 2 Dec 2024 15:31:40 +0100 Subject: [PATCH] feat: attestation privileges control --- .../[attestationId]/edit/page.tsx | 15 +++-- .../organisms/forms/attestation-form.tsx | 67 ++++++++++++++++++- src/lib/api/index.ts | 2 + 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/src/app/(auth)/communities/[id]/attestations/[attestationId]/edit/page.tsx b/src/app/(auth)/communities/[id]/attestations/[attestationId]/edit/page.tsx index 41962fa..8b849dd 100644 --- a/src/app/(auth)/communities/[id]/attestations/[attestationId]/edit/page.tsx +++ b/src/app/(auth)/communities/[id]/attestations/[attestationId]/edit/page.tsx @@ -23,9 +23,12 @@ export default function Page({ useFormStatus(); // todo: add skeleton loader const { data, isLoading } = useQuery(listAttestationsQuery, getQueryClient()); - const attestation = data?.find((com) => com.id === parseInt(params.attestationId)); + const attestation = data?.find( + (com) => com.id === parseInt(params.attestationId) + ); - if (!attestation) return + if (!attestation) return ; + console.log("Attestation", { attestation }); return ( { @@ -37,10 +40,14 @@ export default function Page({ name: attestation.name, description: attestation.description, protected: attestation.protected, + canMintDoi: attestation.canMintDoi, + canUpdateOrcid: attestation.canUpdateOrcid, communityId: attestation.communityId.toString(), imageUrl: attestation.image_url, - ...(attestation.verified_image_url && { verifiedImageUrl: attestation.verified_image_url}) + ...(attestation.verified_image_url && { + verifiedImageUrl: attestation.verified_image_url, + }), }} /> ); -} \ No newline at end of file +} diff --git a/src/components/organisms/forms/attestation-form.tsx b/src/components/organisms/forms/attestation-form.tsx index 9e11e6a..e30ef62 100644 --- a/src/components/organisms/forms/attestation-form.tsx +++ b/src/components/organisms/forms/attestation-form.tsx @@ -71,6 +71,14 @@ const attestationSchema = z.object({ .boolean() .transform((value) => (value.toString() === "true" ? true : false)) .default(false), + canMintDoi: z.coerce + .boolean() + .transform((value) => (value.toString() === "true" ? true : false)) + .default(false), + canUpdateOrcid: z.coerce + .boolean() + .transform((value) => (value.toString() === "true" ? true : false)) + .default(false), }); type FormValues = z.infer; @@ -87,7 +95,7 @@ export default function AttestationForm({ // pending: boolean; }) { const router = useRouter(); - + const form = useForm({ resolver: zodResolver(attestationSchema), defaultValues, @@ -99,6 +107,8 @@ export default function AttestationForm({ formData.append("name", data.name); formData.append("description", data.description); formData.append("protected", data.protected.toString()); + formData.append("canMintDoi", data.canMintDoi.toString()); + formData.append("canUpdateOrcid", data.canUpdateOrcid.toString()); formData.append("communityId", data.communityId); if (data.imageUrl) { @@ -132,7 +142,9 @@ export default function AttestationForm({ getQueryClient().invalidateQueries({ queryKey: [tags.attestations], }); - getQueryClient().invalidateQueries({ queryKey: [{ type: tags.attestations, id: defaultValues?.communityId }], }); + getQueryClient().invalidateQueries({ + queryKey: [{ type: tags.attestations, id: defaultValues?.communityId }], + }); router.back(); // todo: show success toast } @@ -242,6 +254,57 @@ export default function AttestationForm({ )} /> + {isProtected && ( + ( + +
+ + DOI Mint Privilege + + + Authorize this attestation to mint DOI, if a claim on + this attestation gets verified it automatically mints a + DOI for the associated research object. + +
+ + + +
+ )} + /> + )} + {isProtected && ( + ( + +
+ + ORCID Work Record Privilege + + + Authorize this attestation to update ORCID work record, if a claim on + this attestation gets verified it automatically reflects on the user's ORCID work record. + +
+ + + +
+ )} + /> + )} {isProtected && (