Created
October 27, 2024 14:52
-
-
Save yehonatan56/0291d4832b0b55d6792a6b43af726ed6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { createRef, useState } from "react"; | |
| import { useDisclosure } from "@mantine/hooks"; | |
| import { Modal, Button } from "@mantine/core"; | |
| import { addLinkLogic } from "../../logic/links.ts"; | |
| const AddLink = () => { | |
| const [opened, { open, close }] = useDisclosure(false); | |
| const [link, setLink] = useState<string>(""); | |
| const [error, setError] = useState<string>(""); | |
| const [fileState, setFileState] = useState<any>(""); | |
| const file = createRef(); | |
| const submitLink = async () => { | |
| console.log(link); | |
| const res = await addLinkLogic(link, fileState); | |
| if (res.code === 11000) { | |
| setError("Link already exists"); | |
| return; | |
| } | |
| console.log(res); | |
| close(); | |
| }; | |
| // @ts-ignore | |
| return ( | |
| <> | |
| <Modal opened={opened} onClose={close} title="Add link"> | |
| <input | |
| type="text" | |
| value={link} | |
| onChange={(e) => setLink(e.target.value)} | |
| style={{ width: "100%" }} | |
| /> | |
| <input | |
| type="file" | |
| name="file" | |
| id="file" | |
| className="inputfile" | |
| ref={file} | |
| onChange={(e) => setFileState(e.currentTarget.files[0])} | |
| /> | |
| {error && <p style={{ color: "red" }}>{error}</p>} | |
| <Button onClick={() => submitLink()}>Submit</Button> | |
| </Modal> | |
| <Button onClick={open}>Add link</Button> | |
| </> | |
| ); | |
| }; | |
| export default AddLink; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment