diff --git a/.gitignore b/.gitignore index 1437c53f70..e585918c78 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,9 @@ yarn-error.log* .env.development.local .env.test.local .env.production.local +.env # vercel .vercel + +note.txt \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..f7eb6d0c0f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 2, + "semi": false, + "doubleQuote": true +} diff --git a/components/Add.jsx b/components/Add.jsx new file mode 100644 index 0000000000..ef3000165a --- /dev/null +++ b/components/Add.jsx @@ -0,0 +1,140 @@ +import { useState } from "react" +import styles from "../styles/Add.module.css" +import axios from "axios" + +const Add = ({ setClose }) => { + const [file, setFile] = useState(null) + const [title, setTitle] = useState(null) + const [desc, setDesc] = useState(null) + const [prices, setPrices] = useState([]) + const [extraOptions, setExtraOptions] = useState([]) + const [extra, setExtra] = useState(null) + + const changePrice = (e, index) => { + const currentPrices = prices + currentPrices[index] = e.target.value + setPrices(currentPrices) + } + + const handleExtraInput = (e) => { + setExtra({ ...extra, [e.target.name]: e.target.value }) + } + + const handleExtra = (e) => { + setExtraOptions((prev) => [...prev, extra]) + } + + const handleCreate = async () => { + const data = new FormData() + data.append("file", file) + data.append("upload_preset", "uploads") + try { + const uploadRes = await axios.post( + "https://api.cloudinary.com/v1_1/dinwebdev/image/upload", + data + ) + + const { url } = uploadRes.data + const newProduct = { + title, + desc, + prices, + extraOptions, + img: url, + } + + await axios.post("http://localhost:3000/api/products", newProduct) + setClose(true) + } catch (err) { + console.log(err) + } + } + + return ( +
+
+ setClose(true)} className={styles.close}> + X + +

Add a new Pizza

+
+ + setFile(e.target.files[0])} /> +
+
+ + setTitle(e.target.value)} + /> +
+
+ +