модалка предупреждения о удалении + подключение размера, затемнения
This commit is contained in:
parent
f6a49fdfcb
commit
f43ef82c14
53
src/ui_kit/Modal/CropModal/AlertModalDeleteImage.tsx
Normal file
53
src/ui_kit/Modal/CropModal/AlertModalDeleteImage.tsx
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { Box, Button, Modal, Typography, useMediaQuery, useTheme } from "@mui/material";
|
||||||
|
interface Props {
|
||||||
|
open: boolean;
|
||||||
|
cancelDelete: () => void;
|
||||||
|
deleteImage: () => void;
|
||||||
|
}
|
||||||
|
export default ({
|
||||||
|
open,
|
||||||
|
cancelDelete,
|
||||||
|
deleteImage,
|
||||||
|
}: Props) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const isMobile = useMediaQuery(theme.breakpoints.down(450));
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
onClose={cancelDelete}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
top: "50%",
|
||||||
|
left: "50%",
|
||||||
|
transform: "translate(-50%, -50%)",
|
||||||
|
bgcolor: "background.paper",
|
||||||
|
boxShadow: 24,
|
||||||
|
borderRadius: "12px",
|
||||||
|
width: isMobile ? "200px" : "350px",
|
||||||
|
height: "350px",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography sx={{
|
||||||
|
// height: isMobile ? "91px" : "70px",
|
||||||
|
backgroundColor: "#F2F3F7",
|
||||||
|
padding: isMobile ? "25px 20px 24px 20px" : "25px 43px 24px 20px",
|
||||||
|
borderRadius: "8px 8px 0px 0px",
|
||||||
|
color: "#9A9AAF",
|
||||||
|
fontSize: "18px",
|
||||||
|
lineHeight: "21.33px"
|
||||||
|
}}>
|
||||||
|
Вы уверены, что хотите удалить всю картинку и каждую настройку?
|
||||||
|
</Typography>
|
||||||
|
<Button sx={{margin: "25px"}} variant="contained" onClick={cancelDelete}>нет</Button>
|
||||||
|
<Button sx={{margin: "25px"}} variant="outlined" onClick={deleteImage}>да</Button>
|
||||||
|
|
||||||
|
</Box>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
@ -63,9 +63,12 @@ export const CropGeneral: FC<Props> = ({
|
|||||||
cropAspectRatio,
|
cropAspectRatio,
|
||||||
editedImagesChange,
|
editedImagesChange,
|
||||||
}) => {
|
}) => {
|
||||||
|
console.log(editedImage)
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(786));
|
const isMobile = useMediaQuery(theme.breakpoints.down(786));
|
||||||
|
|
||||||
|
const {crop, darken, rotate} = editedImage.newRules;
|
||||||
|
|
||||||
const cropImageElementRef = useRef<HTMLImageElement>(null);
|
const cropImageElementRef = useRef<HTMLImageElement>(null);
|
||||||
|
|
||||||
const [imageWidth, setImageWidth] = useState<number | null>(null);
|
const [imageWidth, setImageWidth] = useState<number | null>(null);
|
||||||
@ -140,7 +143,7 @@ export const CropGeneral: FC<Props> = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ReactCrop
|
<ReactCrop
|
||||||
crop={editedImage.newRules.crop}
|
crop={crop}
|
||||||
onChange={(_, percentCrop) => editedImagesChange((old) => ({
|
onChange={(_, percentCrop) => editedImagesChange((old) => ({
|
||||||
newRules: {
|
newRules: {
|
||||||
...old.newRules,
|
...old.newRules,
|
||||||
@ -216,7 +219,7 @@ export const CropGeneral: FC<Props> = ({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
flexDirection: isMobile ? "column": "",
|
flexDirection: isMobile ? "column": "",
|
||||||
width: isMobile ? "100%": "",
|
width: isMobile ? "100%": "auto",
|
||||||
gap: "24px",
|
gap: "24px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -231,7 +234,7 @@ export const CropGeneral: FC<Props> = ({
|
|||||||
width: isMobile ? undefined : "248px",
|
width: isMobile ? undefined : "248px",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={55}
|
value={crop.width}
|
||||||
min={1}
|
min={1}
|
||||||
max={100}
|
max={100}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
@ -252,7 +255,7 @@ export const CropGeneral: FC<Props> = ({
|
|||||||
width: isMobile ? undefined : "248px",
|
width: isMobile ? undefined : "248px",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
value={52}
|
value={darken}
|
||||||
min={0}
|
min={0}
|
||||||
max={100}
|
max={100}
|
||||||
step={1}
|
step={1}
|
||||||
|
@ -39,9 +39,17 @@ export const CropModal: FC<CropModalProps> = ({
|
|||||||
), [currentStep])
|
), [currentStep])
|
||||||
|
|
||||||
const editedImagesChange: EditedImagesChangeType = (changed) => {
|
const editedImagesChange: EditedImagesChangeType = (changed) => {
|
||||||
|
console.log("n*")
|
||||||
setEditedImages(old => {
|
setEditedImages(old => {
|
||||||
old[currentStepName] = { ...old[currentStepName], ...changed(old[currentStepName]) }
|
console.log("n currentStepName")
|
||||||
return old
|
console.log(currentStepName)
|
||||||
|
console.log("n old[currentStepName]")
|
||||||
|
console.log(old[currentStepName])
|
||||||
|
const newData = { ...old };
|
||||||
|
newData[currentStepName] = { ...old[currentStepName], ...changed(old[currentStepName]) };
|
||||||
|
console.log("newData[currentStepName]")
|
||||||
|
console.log(newData[currentStepName])
|
||||||
|
return newData;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const resetImage = () => {
|
const resetImage = () => {
|
||||||
|
@ -47,6 +47,8 @@ export default function WorkSpace({
|
|||||||
modalModels[currentStepName]
|
modalModels[currentStepName]
|
||||||
), [currentStepName]);
|
), [currentStepName]);
|
||||||
|
|
||||||
|
console.log(" промежуточный рендер которому должно быть похуй")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box
|
<Box
|
||||||
@ -90,7 +92,7 @@ export default function WorkSpace({
|
|||||||
{currentModel.icon}
|
{currentModel.icon}
|
||||||
</Box>
|
</Box>
|
||||||
<IconButton
|
<IconButton
|
||||||
// onClick={onDeleteClick}
|
onClick={onDeleteClick}
|
||||||
sx={{
|
sx={{
|
||||||
height: "24px",
|
height: "24px",
|
||||||
width: "24px",
|
width: "24px",
|
||||||
@ -100,7 +102,7 @@ export default function WorkSpace({
|
|||||||
mb:"5px",
|
mb:"5px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AmoTrash></AmoTrash>
|
<AmoTrash/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
DEFAULTCROPRULES,
|
DEFAULTCROPRULES,
|
||||||
} from "@/model/CropModal/CropModal"
|
} from "@/model/CropModal/CropModal"
|
||||||
import { isImageBlobAGifFile } from "@/utils/isImageBlobAGifFile";
|
import { isImageBlobAGifFile } from "@/utils/isImageBlobAGifFile";
|
||||||
|
import AlertModalDeleteImage from "./AlertModalDeleteImage"
|
||||||
|
|
||||||
const workSpaceTypesList: WorkSpaceTypesList = {
|
const workSpaceTypesList: WorkSpaceTypesList = {
|
||||||
images: [
|
images: [
|
||||||
@ -114,6 +115,9 @@ export const CropModalInit: FC<CropOnOpenType> = ({
|
|||||||
|
|
||||||
const [acceptedOriginalImageUrl, setOriginalImageUrl] = useState("");
|
const [acceptedOriginalImageUrl, setOriginalImageUrl] = useState("");
|
||||||
const [editedImages, setEditedImages] = useState<EditedImages>({} as EditedImages);
|
const [editedImages, setEditedImages] = useState<EditedImages>({} as EditedImages);
|
||||||
|
const [readyDelete, setReadyDelete] = useState(false);
|
||||||
|
console.log("editedImages index")
|
||||||
|
console.log(editedImages)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//Если нам не дали с чем работать, то и работать не нужно
|
//Если нам не дали с чем работать, то и работать не нужно
|
||||||
@ -138,7 +142,7 @@ export const CropModalInit: FC<CropOnOpenType> = ({
|
|||||||
if (questionId) {
|
if (questionId) {
|
||||||
if (questionType) {
|
if (questionType) {
|
||||||
if (Boolean(editedUrlImagesList)) {
|
if (Boolean(editedUrlImagesList)) {
|
||||||
|
|
||||||
const newEditedImagesList = {} as EditedImages;
|
const newEditedImagesList = {} as EditedImages;
|
||||||
|
|
||||||
for (let key in editedUrlImagesList) {
|
for (let key in editedUrlImagesList) {
|
||||||
@ -170,7 +174,7 @@ export const CropModalInit: FC<CropOnOpenType> = ({
|
|||||||
selfClose?.()
|
selfClose?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCropModalDeleteImageClick: CropOnDeleteIamgeClick = () => {
|
const handleCropModalDeleteImageClick = () => {
|
||||||
|
|
||||||
//сохранить пустую строку и дефолтные настройки картинки в самом вопросе, не информируя БД о удалении картинки
|
//сохранить пустую строку и дефолтные настройки картинки в самом вопросе, не информируя БД о удалении картинки
|
||||||
selfClose?.()
|
selfClose?.()
|
||||||
@ -194,15 +198,24 @@ export const CropModalInit: FC<CropOnOpenType> = ({
|
|||||||
|
|
||||||
if (acceptedOriginalImageUrl.length === 0) return <></>
|
if (acceptedOriginalImageUrl.length === 0) return <></>
|
||||||
|
|
||||||
return <CropModal
|
return (
|
||||||
editedImages={editedImages}
|
<>
|
||||||
workSpaceTypes={workSpaceTypesList[questionType]}
|
<CropModal
|
||||||
originalImageUrl={acceptedOriginalImageUrl}
|
editedImages={editedImages}
|
||||||
|
workSpaceTypes={workSpaceTypesList[questionType]}
|
||||||
|
originalImageUrl={acceptedOriginalImageUrl}
|
||||||
|
|
||||||
setEditedImages={setEditedImages}
|
setEditedImages={setEditedImages}
|
||||||
onSaveImageClick={saveImagesAndRules}
|
onSaveImageClick={saveImagesAndRules}
|
||||||
closeCropModal={closeModal}
|
closeCropModal={closeModal}
|
||||||
onDeleteClick={handleCropModalDeleteImageClick}
|
onDeleteClick={() => setReadyDelete(true)}
|
||||||
/>
|
/>
|
||||||
|
<AlertModalDeleteImage
|
||||||
|
open={readyDelete}
|
||||||
|
cancelDelete={() => setReadyDelete(false)}
|
||||||
|
deleteImage={handleCropModalDeleteImageClick}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user