diff --git a/src/app/(dashboard)/etage/CreateEtage.jsx b/src/app/(dashboard)/etage/CreateEtage.jsx index 2d16cebac618d8f66a40d831cfda4d2e19dca3e3..5259b4902664544db649bf3f4f390aced4825e2b 100644 --- a/src/app/(dashboard)/etage/CreateEtage.jsx +++ b/src/app/(dashboard)/etage/CreateEtage.jsx @@ -1,3 +1,4 @@ +/* eslint-disable @next/next/no-img-element */ 'use client' import Loader from '@/components/Loader/Loader' import React, { useRef, useState, useEffect } from 'react' @@ -5,7 +6,9 @@ import fetchRequest from '../../lib/fetchRequest' import { useNotification } from "@/context/NotificationContext"; import CancelIcon from "@/static/image/svg/cancel.svg" import CheckIcon from "@/static/image/svg/check.svg" - +import ImageIcon from "@/static/image/svg/image.svg" +import ColoredImageIcon from "@/static/image/svg/image2.svg" +import CrossIcon from "@/static/image/svg/cancel.svg" const CreateEtage = ({ appendEtage, cancelCreate }) => { const [isLoading, setIsLoading] = useState(false) @@ -15,12 +18,17 @@ const CreateEtage = ({ appendEtage, cancelCreate }) => { setNumeroEtage(event.target.value) } const inputRef = useRef(null) + const imageInput = useRef(null) + const [image, setImage] = useState(null) const handleSubmit = async (event) => { event.preventDefault() setIsLoading(true) + const formData = new FormData() + formData.append("numero", numeroEtage) + formData.append("image", image) const { data, errors, isSuccess } = await fetchRequest("/zoaning/etages/", { method: "POST", - body: JSON.stringify({ numero: numeroEtage }) + body: formData, }) if (isSuccess) { setIsLoading(false) @@ -36,6 +44,13 @@ const CreateEtage = ({ appendEtage, cancelCreate }) => { } else { setIsLoading(false) if (errors.type === "ValidationError") { + if (errors.detail.image) { + toggleNotification({ + type: "warning", + message: "Le type de l'image n'est pas supporté", + visible: true, + }) + } if (errors.detail.name) { toggleNotification({ type: "warning", @@ -93,9 +108,88 @@ const CreateEtage = ({ appendEtage, cancelCreate }) => { } }, []) + + const removeImage = () => { + imageInput.current.value = ""; + setImage(null); + setIsDisplayingImage(false) + }; + + const handleChangeImage = (e) => { + if (imageInput.current.value !== "") { + const supportedType = ["image/jpg", "image/jpeg", "image/png"]; + if (supportedType.includes(imageInput.current.files[0].type)) { + setImage(imageInput.current.files[0]); + } else { + removeImage(); + setIsDisplayingImage(false) + toggleNotification({ + type: "warning", + message: "Le type de l'image n'est pas supporté", + visible: true + }) + } + } else { + setImage(null); + setIsDisplayingImage(false) + } + }; + const [isDisplayingImage, setIsDisplayingImage] = useState(false) + const viewImage = () => { + setIsDisplayingImage(true) + } + return - + + + + {(!image) && <> + + } + + + + {(image) && <> +
+
+
+ +
+
+

{image.name}

+

{Math.round((image.size / (1024 * 1024)) * 100) / 100}Mo

+
+
+

Voir l'image

+
+ {(isDisplayingImage) &&
+
+
setIsDisplayingImage(false)} className='ml-auto relative bottom-3'> + +
+
+ User uploaded +
+
+
} +
+
+ +
+
+
+
+ }
diff --git a/src/app/(dashboard)/etage/EtageTableRow.jsx b/src/app/(dashboard)/etage/EtageTableRow.jsx index ff162b580369800b60cdeb49623f554d924fce04..0cc0af12b1223920ff1f2a5ae24fa82c30988ab1 100644 --- a/src/app/(dashboard)/etage/EtageTableRow.jsx +++ b/src/app/(dashboard)/etage/EtageTableRow.jsx @@ -1,3 +1,4 @@ +/* eslint-disable @next/next/no-img-element */ 'use client' import React, { useEffect, useRef, useState } from 'react' import fetchRequest from '../../lib/fetchRequest' @@ -8,7 +9,9 @@ import CancelIcon from "@/static/image/svg/cancel.svg" import CheckIcon from "@/static/image/svg/check.svg" import { useNotification } from '@/context/NotificationContext' import ConfirmationModal from '../../ui/ConfirmationModal' -const EtageTableRow = ({ id, numero, setEtages }) => { +import CrossIcon from "@/static/image/svg/cancel.svg" + +const EtageTableRow = ({ id, numero, setEtages, image }) => { const [numeroEtage, setNumeroEtage] = useState(numero) const [loadingStatus, setLoadingStatus] = useState(false) const { toggleNotification } = useNotification() @@ -68,11 +71,33 @@ const EtageTableRow = ({ id, numero, setEtages }) => { document.removeEventListener("click", handleUpdateBlur); } } + const [isDisplayingImage, setIsDisplayingImage] = useState(false) + const viewImage = () => { + setIsDisplayingImage(true) + } return ( <> - setNumeroEtage(event.target.value)} defaultValue={numero} type='text' className='w-full border-0 rounded-md px-2 enabled:drop-shadow border-none enabled:bg-gray-100 disabled:bg-transparent duration-100 h-10 outline-none' /> + setNumeroEtage(event.target.value)} defaultValue={numero} type='text' className='w-full min-w-80 border-0 rounded-md px-2 enabled:drop-shadow border-none enabled:bg-gray-100 disabled:bg-transparent duration-100 h-10 outline-none' /> + + + {(isDisplayingImage && image) &&
+
+
setIsDisplayingImage(false)} className='ml-auto relative bottom-3'> + +
+
+ User uploaded +
+
+
} + {!image &&

+ Aucune image n'est associée à cet étage. +

} + {(image) &&
+

Voir l'image

+
}
diff --git a/src/app/(dashboard)/etage/page.jsx b/src/app/(dashboard)/etage/page.jsx index 8deae510305aed6510cf98a804356ea6650668fe..c4dc6c726a9c501f76d55e480dc3723e1625271e 100644 --- a/src/app/(dashboard)/etage/page.jsx +++ b/src/app/(dashboard)/etage/page.jsx @@ -47,6 +47,7 @@ const Etage = () => { + {(isCreating) && setIsCreating(false)} appendEtage={appendEtage} />} diff --git a/src/app/lib/fetchRequest.js b/src/app/lib/fetchRequest.js index db2aa42c283fbd6f28b038af117d253871396c2c..6ad19f127dc48270e51e39674f2811c72bfb8bf7 100644 --- a/src/app/lib/fetchRequest.js +++ b/src/app/lib/fetchRequest.js @@ -11,7 +11,6 @@ const fetchRequest = async (url, options = {}) => { ...options.headers, // add authorization header with token if there is jwtDecrypted.sessionData.token Authorization: jwtDecrypted?.sessionData?.token ? `Token ${jwtDecrypted.sessionData.token}` : undefined, - 'Content-Type': 'application/json', }; const response = await fetch(`${BASE_URL}${url}`, { diff --git a/src/static/image/svg/image.svg b/src/static/image/svg/image.svg new file mode 100644 index 0000000000000000000000000000000000000000..0f7ca5d797cd4bbe659c28de3b59f74a8a4c9a09 --- /dev/null +++ b/src/static/image/svg/image.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/static/image/svg/image2.svg b/src/static/image/svg/image2.svg new file mode 100644 index 0000000000000000000000000000000000000000..5d8ea1ce901c9ba7cacd89b71081f2ad50ecac0f --- /dev/null +++ b/src/static/image/svg/image2.svg @@ -0,0 +1 @@ + \ No newline at end of file
Numéro ÉtageImage Actions