Guest User

Untitled

a guest
Apr 13th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. "use client";
  2. import {
  3. Dialog,
  4. DialogContent,
  5. DialogDescription,
  6. DialogHeader,
  7. DialogTitle,
  8. DialogTrigger,
  9. } from "@/components/ui/dialog";
  10. import {
  11. Form,
  12. FormControl,
  13. FormField,
  14. FormItem,
  15. FormLabel,
  16. FormMessage,
  17. } from "@/components/ui/form";
  18.  
  19. import { FileUp } from "lucide-react";
  20. import { useState } from "react";
  21. import { useForm } from "react-hook-form";
  22. import { Input } from "@/components/ui/input";
  23. import { Button } from "@/components/ui/button";
  24. import { zodResolver } from "@hookform/resolvers/zod";
  25. import * as z from "zod";
  26. import { handleSubmits } from "./submit-assignment";
  27.  
  28. export default function SubmitAssignment({ assignementid }) {
  29. const [open, setOpen] = useState(false);
  30.  
  31. const formSchema = z.object({
  32. file: z
  33. .any()
  34. .refine((files) => files?.length == 1, "File is required.")
  35. .refine(
  36. (files) => files?.[0]?.type == "application/pdf",
  37. "File must be a PDF."
  38. ),
  39. });
  40.  
  41. const form = useForm({
  42. resolver: zodResolver(formSchema),
  43. });
  44.  
  45. const fileRef = form.register("file");
  46. const onSubmit = form.handleSubmit((project) => {
  47. handleSubmits({ project, assignementid }); // when i console log here it prints but when i try to handle in some other file it doesnt work
  48. });
  49.  
  50. return (
  51. <Dialog open={open} onOpenChange={setOpen}>
  52. <Button onClick={() => setOpen(true)}>Upload</Button>
  53. <DialogContent className=" bg-background sm:max-w-[625px]">
  54. <DialogHeader>
  55. <DialogTitle className="tracking-wide text-2xl">
  56. Upload your assignment
  57. </DialogTitle>
  58. </DialogHeader>
  59. <Form {...form}>
  60. <form onSubmit={form.handleSubmit(onSubmit)} className="w-full p-10">
  61. <FormField
  62. control={form.control}
  63. name="file"
  64. render={({ field }) => (
  65. <FormItem>
  66. <FormLabel>File</FormLabel>
  67. <FormControl>
  68. <Input
  69. className="border-2 border-dashed h-56 bg-white hover:bg-slate-100 rounded flex flex-col items-center justify-center text-center cursor-pointer"
  70. type="file"
  71. accept="application/pdf"
  72. {...fileRef}
  73. />
  74. </FormControl>
  75. <FormMessage />
  76. </FormItem>
  77. )}
  78. />
  79. <Button className="mt-3" type="submit">
  80. Submit
  81. </Button>
  82. </form>
  83. </Form>
  84. </DialogContent>
  85. </Dialog>
  86. );
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment