Feature/update api

This commit is contained in:
2024-11-05 07:09:13 +00:00
committed by AmirHossein Mahmoodi
parent 56196f33c7
commit b64a1c93e9
83 changed files with 4066 additions and 3123 deletions

View File

@@ -1,19 +1,19 @@
import {Box, Button, FormHelperText, TextField, Typography} from "@mui/material";
import {useTranslations} from "next-intl";
import { Box, Button, FormHelperText, TextField, Typography } from "@mui/material";
import { useTranslations } from "next-intl";
import Image from "next/image";
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
import {useRef, useState} from "react";
import { useRef, useState } from "react";
const UploadSystem = ({
fieldName,
default_image,
helperText,
error,
setFieldValue,
imageAlt,
label,
enableDelete
}) => {
fieldName,
default_image,
helperText,
error,
setFieldValue,
imageAlt,
label,
enableDelete,
}) => {
const t = useTranslations();
const fileInputRef = useRef(null);
const [selectedImage, setSelectedImage] = useState(default_image || "/images/upload-image.svg");
@@ -32,19 +32,21 @@ const UploadSystem = ({
};
// end upload files
const uploadBoxStyle = error ? {
cursor: "pointer",
objectFit: "contain",
border: "1px dashed #d32f2f",
borderRadius: "5px",
padding: "5px",
} : {
cursor: "pointer",
objectFit: "contain",
border: "1px dashed #e1e1e1",
borderRadius: "5px",
padding: "5px",
}
const uploadBoxStyle = error
? {
cursor: "pointer",
objectFit: "contain",
border: "1px dashed #d32f2f",
borderRadius: "5px",
padding: "5px",
}
: {
cursor: "pointer",
objectFit: "contain",
border: "1px dashed #e1e1e1",
borderRadius: "5px",
padding: "5px",
};
const handleClick = () => {
fileInputRef.current.click();
@@ -55,7 +57,7 @@ const UploadSystem = ({
};
return (
<Box sx={{my: 2}}>
<Box sx={{ my: 2 }}>
<Typography
margin={1}
sx={{
@@ -67,9 +69,7 @@ const UploadSystem = ({
>
{label}
</Typography>
<Box sx={{position: "relative"}}>
</Box>
<Box sx={{ position: "relative" }}></Box>
{selectedImage === "/images/upload-image.svg" || selectedImage === default_image ? (
<Image
src={selectedImage}
@@ -100,7 +100,7 @@ const UploadSystem = ({
alignItems: "center",
justifyContent: "center",
width: "200px",
height: "200px"
height: "200px",
}}
onClick={handleClick}
>
@@ -113,7 +113,7 @@ const UploadSystem = ({
textAlign: "center",
display: "flex",
justifyContent: "end",
overflow: "hidden"
overflow: "hidden",
}}
textAlign="center"
>
@@ -126,25 +126,29 @@ const UploadSystem = ({
id="avatar-upload"
type="file"
accept="image/*"
style={{display: "none"}}
style={{ display: "none" }}
onChange={(e) => handleUploadChange(e)}
inputRef={fileInputRef}
/>
{enableDelete ? <Button
sx={{
width: "100%",
borderTopLeftRadius: "unset",
borderTopRightRadius: "unset",
}}
color="error"
disabled={selectedImage === "/images/upload-image.svg"}
endIcon={<DeleteForeverIcon/>}
variant="contained"
onClick={handleDeleteImage}
>
{t("delete")}
</Button> : ""}
<FormHelperText sx={{color: "#d32f2f"}}>{helperText}</FormHelperText>
{enableDelete ? (
<Button
sx={{
width: "100%",
borderTopLeftRadius: "unset",
borderTopRightRadius: "unset",
}}
color="error"
disabled={selectedImage === "/images/upload-image.svg"}
endIcon={<DeleteForeverIcon />}
variant="contained"
onClick={handleDeleteImage}
>
{t("delete")}
</Button>
) : (
""
)}
<FormHelperText sx={{ color: "#d32f2f" }}>{helperText}</FormHelperText>
</Box>
);
};