-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from eight-labs/form-cards
Add Form cards
- Loading branch information
Showing
7 changed files
with
185 additions
and
20 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/app/(main)/dashboard/_components/delete-form-dialog.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,72 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog"; | ||
import { TrashIcon } from "@radix-ui/react-icons"; | ||
import { useRouter } from "next/navigation"; | ||
import React from "react"; | ||
import { toast } from "sonner"; | ||
|
||
import { api } from "~/trpc/react"; | ||
|
||
type DeleteFormDialogProps = { | ||
formId: string; | ||
}; | ||
|
||
export function DeleteFormDialog({ formId }: DeleteFormDialogProps) { | ||
const [open, setOpen] = React.useState(false); | ||
|
||
const router = useRouter(); | ||
const deleteFormMutation = api.form.delete.useMutation(); | ||
|
||
const handleDelete = async () => { | ||
deleteFormMutation.mutate( | ||
{ id: formId }, | ||
{ | ||
onSuccess: () => { | ||
router.refresh(); | ||
toast.success("Form deleted successfully"); | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogTrigger asChild> | ||
<div className="group rounded-md bg-gray-100 p-2 hover:cursor-pointer dark:bg-gray-900"> | ||
<TrashIcon className="h-4 w-4 duration-300 group-hover:text-red-500 dark:text-white" /> | ||
</div> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>Are you sure you want to delete this form?</DialogTitle> | ||
<DialogDescription> | ||
This will delete all associated submissions and cannot be undone. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<div className="mt-3 flex w-full gap-4"> | ||
<Button | ||
variant="outline" | ||
className="w-full" | ||
onClick={() => setOpen(false)} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="destructive" | ||
className="w-full" | ||
onClick={handleDelete} | ||
> | ||
Delete | ||
</Button> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
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,81 @@ | ||
import { CopyIcon } from "@radix-ui/react-icons"; | ||
import Link from "next/link"; | ||
import { toast } from "sonner"; | ||
|
||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { type RouterOutputs } from "@/trpc/shared"; | ||
|
||
import { DeleteFormDialog } from "./delete-form-dialog"; | ||
|
||
type FormCardProp = { | ||
form: RouterOutputs["form"]["userForms"][number]; | ||
}; | ||
|
||
export function FormCard({ form }: FormCardProp) { | ||
const handleCopyAction = async () => { | ||
await navigator.clipboard.writeText(form.id); | ||
toast("Copied to clipboard", { | ||
icon: <CopyIcon className="h-4 w-4" />, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Card> | ||
<CardHeader> | ||
<div className="flex items-center justify-between"> | ||
<div> | ||
<CardTitle className="text-lg">{form.title}</CardTitle> | ||
<div className="flex items-center gap-2"> | ||
<p className="text-sm text-muted-foreground">{form.id}</p> | ||
<CopyIcon | ||
className="h-4 w-4 cursor-pointer text-muted-foreground transition-transform hover:scale-110 hover:transform" | ||
onClick={handleCopyAction} | ||
/> | ||
</div> | ||
</div> | ||
<DeleteFormDialog formId={form.id} /> | ||
</div> | ||
</CardHeader> | ||
<CardContent> | ||
<h3 className="mb-4 font-semibold text-muted-foreground"> | ||
Submissions | ||
</h3> | ||
<div className="flex flex-col gap-3"> | ||
<div className="flex items-center justify-between"> | ||
<p className="text-sm text-muted-foreground"> | ||
<span className="text-muted-foreground">Monthly</span> | ||
</p> | ||
<p>343</p> | ||
</div> | ||
<div className="flex items-center justify-between"> | ||
<p className="text-sm text-muted-foreground">Last month</p> | ||
<p>24</p> | ||
</div> | ||
<div className="flex items-center justify-between"> | ||
<p className="text-sm text-muted-foreground">All time</p> | ||
<p>531</p> | ||
</div> | ||
</div> | ||
</CardContent> | ||
<CardFooter className="flex items-center justify-between"> | ||
<div className="flex items-center gap-1"> | ||
<p className="text-sm text-muted-foreground"> | ||
Last submission: 2/12/2021 | ||
</p> | ||
</div> | ||
<Link | ||
href={`/form/s/${form.id}`} | ||
className="text-sm underline underline-offset-2" | ||
> | ||
View all | ||
</Link> | ||
</CardFooter> | ||
</Card> | ||
); | ||
} |
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
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