Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use client";
- import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
- } from "@/components/ui/dialog";
- import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
- } from "@/components/ui/form";
- import { FileUp } from "lucide-react";
- import { useState } from "react";
- import { useForm } from "react-hook-form";
- import { Input } from "@/components/ui/input";
- import { Button } from "@/components/ui/button";
- import { zodResolver } from "@hookform/resolvers/zod";
- import * as z from "zod";
- import { handleSubmits } from "./submit-assignment";
- export default function SubmitAssignment({ assignementid }) {
- const [open, setOpen] = useState(false);
- const formSchema = z.object({
- file: z
- .any()
- .refine((files) => files?.length == 1, "File is required.")
- .refine(
- (files) => files?.[0]?.type == "application/pdf",
- "File must be a PDF."
- ),
- });
- const form = useForm({
- resolver: zodResolver(formSchema),
- });
- const fileRef = form.register("file");
- const onSubmit = form.handleSubmit((project) => {
- handleSubmits({ project, assignementid }); // when i console log here it prints but when i try to handle in some other file it doesnt work
- });
- return (
- <Dialog open={open} onOpenChange={setOpen}>
- <Button onClick={() => setOpen(true)}>Upload</Button>
- <DialogContent className=" bg-background sm:max-w-[625px]">
- <DialogHeader>
- <DialogTitle className="tracking-wide text-2xl">
- Upload your assignment
- </DialogTitle>
- </DialogHeader>
- <Form {...form}>
- <form onSubmit={form.handleSubmit(onSubmit)} className="w-full p-10">
- <FormField
- control={form.control}
- name="file"
- render={({ field }) => (
- <FormItem>
- <FormLabel>File</FormLabel>
- <FormControl>
- <Input
- 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"
- type="file"
- accept="application/pdf"
- {...fileRef}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <Button className="mt-3" type="submit">
- Submit
- </Button>
- </form>
- </Form>
- </DialogContent>
- </Dialog>
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment