From ad16705a5f5aa7b047abf9ead4fb2e8855257c99 Mon Sep 17 00:00:00 2001 From: Bob Burningham Date: Mon, 13 Nov 2023 00:29:05 -0800 Subject: [PATCH] fixed typo in file names --- components/modals/message-file-modal.tsx | 117 +++++++++++++++++++ components/modals/message-file-modal.tsx.tsx | 114 ------------------ hooks/{user-origin.ts => use-origin.ts} | 5 +- 3 files changed, 119 insertions(+), 117 deletions(-) create mode 100644 components/modals/message-file-modal.tsx delete mode 100644 components/modals/message-file-modal.tsx.tsx rename hooks/{user-origin.ts => use-origin.ts} (86%) diff --git a/components/modals/message-file-modal.tsx b/components/modals/message-file-modal.tsx new file mode 100644 index 0000000..247d80b --- /dev/null +++ b/components/modals/message-file-modal.tsx @@ -0,0 +1,117 @@ +"use client"; + +import axios from "axios"; +import qs from "query-string"; +import * as z from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; + +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, +} from "@/components/ui/form"; +import { Button } from "@/components/ui/button"; +import { FileUpload } from "@/components/file-upload"; +import { useRouter } from "next/navigation"; +import { useModal } from "@/hooks/use-modal-store"; + +const formSchema = z.object({ + fileUrl: z.string().min(1, { + message: "Attachment is required." + }) +}); + +export const MessageFileModal = () => { + const { isOpen, onClose, type, data } = useModal(); + const router = useRouter(); + + const isModalOpen = isOpen && type === "messageFile"; + const { apiUrl, query } = data; + + const form = useForm({ + resolver: zodResolver(formSchema), + defaultValues: { + fileUrl: "", + } + }); + + const handleClose = () => { + form.reset(); + onClose(); + } + + const isLoading = form.formState.isSubmitting; + + const onSubmit = async (values: z.infer) => { + try { + const url = qs.stringifyUrl({ + url: apiUrl || "", + query, + }); + + await axios.post(url, { + ...values, + content: values.fileUrl, + }); + + form.reset(); + router.refresh(); + handleClose(); + } catch (error) { + console.log(error); + } + } + + return ( + + + + + Add an attachment + + + Send a file as a message + + +
+ +
+
+ ( + + + + + + )} + /> +
+
+ + + +
+ +
+
+ ) +} \ No newline at end of file diff --git a/components/modals/message-file-modal.tsx.tsx b/components/modals/message-file-modal.tsx.tsx deleted file mode 100644 index 82ec705..0000000 --- a/components/modals/message-file-modal.tsx.tsx +++ /dev/null @@ -1,114 +0,0 @@ -"use client"; - -import axios from "axios"; -import qs from "query-string"; -import * as z from "zod"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm } from "react-hook-form"; - -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog"; -import{ - Form, - FormControl, - FormField, - FormItem, -} from "@/components/ui/form"; -import { Button } from "@/components/ui/button"; -import { FileUpload } from "@/components/file-upload"; -import { useRouter } from "next/navigation"; -import { useModal } from "@/hooks/use-modal-store"; - -const formSchema = z.object({ - fileUrl: z.string().min(1, { - message: "Attachment is required", - }), -}); - -export const MessageFileModal = () => { - const {isOpen, onClose, type, data} = useModal(); - const router = useRouter(); - - const isModalOpen = isOpen && type === "messageFile"; - const { apiUrl, query } = data; - - const form = useForm({ - resolver: zodResolver(formSchema), - defaultValues: { - fileUrl: "", - } - }); - - const handleClose = () => { - form.reset(); - onClose(); - } - - const isLoading = form.formState.isSubmitting; - - const onSubmit = async (values: z.infer) => { - try { - const url = qs.stringifyUrl({ - url: apiUrl || "", - query, - }) - - await axios.post(url, {...values, content: values.fileUrl,}); - - form.reset(); - router.refresh(); - handleClose(); - } catch (error) { - console.error(error); - } - } - - return ( - - - - - Add an attachment - - - Send a file as a message - - -
- -
-
- ( - - - - - - )} - /> -
-
- - - -
- -
-
- ) -} \ No newline at end of file diff --git a/hooks/user-origin.ts b/hooks/use-origin.ts similarity index 86% rename from hooks/user-origin.ts rename to hooks/use-origin.ts index f4d1a63..5b8c534 100644 --- a/hooks/user-origin.ts +++ b/hooks/use-origin.ts @@ -1,15 +1,14 @@ -import { useEffect, useState } from "react"; +import { useEffect, useState } from "react" export const useOrigin = () => { const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); - }, []); const origin = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; - + if (!mounted) { return ""; }