Skip to content

Commit

Permalink
feat: attestation privileges control
Browse files Browse the repository at this point in the history
  • Loading branch information
shadrach-tayo committed Dec 2, 2024
1 parent 370ee9a commit 6429fdf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NotFoundError />
if (!attestation) return <NotFoundError />;
console.log("Attestation", { attestation });
return (
<AttestationForm
formAction={(formdata) => {
Expand All @@ -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,
}),
}}
/>
);
}
}
67 changes: 65 additions & 2 deletions src/components/organisms/forms/attestation-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof attestationSchema>;
Expand All @@ -87,7 +95,7 @@ export default function AttestationForm({
// pending: boolean;
}) {
const router = useRouter();

const form = useForm<FormValues>({
resolver: zodResolver(attestationSchema),
defaultValues,
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -242,6 +254,57 @@ export default function AttestationForm({
</FormItem>
)}
/>
{isProtected && (
<FormField
control={form.control}
name="canMintDoi"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel className="text-base">
DOI Mint Privilege
</FormLabel>
<FormDescription>
Authorize this attestation to mint DOI, if a claim on
this attestation gets verified it automatically mints a
DOI for the associated research object.
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</FormItem>
)}
/>
)}
{isProtected && (
<FormField
control={form.control}
name="canUpdateOrcid"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel className="text-base">
ORCID Work Record Privilege
</FormLabel>
<FormDescription>
Authorize this attestation to update ORCID work record, if a claim on
this attestation gets verified it automatically reflects on the user&apos;s ORCID work record.
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</FormItem>
)}
/>
)}
{isProtected && (
<FormField
control={form.control}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export interface Attestation {
verified_image_url: any;
templateId: any;
protected: boolean;
canMintDoi: boolean;
canUpdateOrcid: boolean;
createdAt: string;
updatedAt: string;
community: {
Expand Down

0 comments on commit 6429fdf

Please sign in to comment.