Modals #44
@@ -58,11 +58,14 @@ const Day = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This handles the modal for this date.
|
// This handles the modal for the day.
|
||||||
const [isOpen, setIsOpen] = useState<boolean>(false);
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
const [stickerState, setStickerState] = useState<StickerVal>(sticker);
|
const [stickerState, setStickerState] = useState<StickerVal>(sticker);
|
||||||
|
|
||||||
|
// The step the modal is at.
|
||||||
|
const [step, setStep] = useState<number>(0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Add logic to remove the onClick within overflow dates.
|
* TODO: Add logic to remove the onClick within overflow dates.
|
||||||
* Do not give dates for the next month an onClick.
|
* Do not give dates for the next month an onClick.
|
||||||
@@ -114,7 +117,10 @@ const Day = ({
|
|||||||
border="1px solid #0068ff"
|
border="1px solid #0068ff"
|
||||||
w="100%"
|
w="100%"
|
||||||
h="100%"
|
h="100%"
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={() => {
|
||||||
|
setStep(0);
|
||||||
|
setIsOpen(true);
|
||||||
|
}}
|
||||||
alignContent="center"
|
alignContent="center"
|
||||||
justifyContent="flex-start"
|
justifyContent="flex-start"
|
||||||
pt={2}
|
pt={2}
|
||||||
@@ -157,6 +163,8 @@ const Day = ({
|
|||||||
updateIsOpen={setIsOpen}
|
updateIsOpen={setIsOpen}
|
||||||
updateSticker={setStickerState}
|
updateSticker={setStickerState}
|
||||||
currSticker={stickerState}
|
currSticker={stickerState}
|
||||||
|
step={step}
|
||||||
|
updateStep={setStep}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</StickersContextProvider>
|
</StickersContextProvider>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
HStack,
|
HStack,
|
||||||
Text
|
Text
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import React, { Fragment, useState, useContext, useEffect } from "react";
|
import React, { useState, useContext } from "react";
|
||||||
import { format, isSameDay } from "date-fns";
|
import { format, isSameDay } from "date-fns";
|
||||||
import DemoStickers from "../stickers/DemoStickers";
|
import DemoStickers from "../stickers/DemoStickers";
|
||||||
import { StickersContext } from "../../../contexts/StickerContext";
|
import { StickersContext } from "../../../contexts/StickerContext";
|
||||||
@@ -21,23 +21,28 @@ interface AddStickerProps {
|
|||||||
date: Date;
|
date: Date;
|
||||||
updateSticker: React.Dispatch<React.SetStateAction<StickerVal>>;
|
updateSticker: React.Dispatch<React.SetStateAction<StickerVal>>;
|
||||||
currSticker: StickerVal;
|
currSticker: StickerVal;
|
||||||
|
step: number;
|
||||||
|
updateStep: React.Dispatch<React.SetStateAction<number>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles adding and modifying the stickers for the given month.
|
* Handles adding and modifying the stickers for the given month.
|
||||||
* @param props the props for this component.
|
* @param {boolean} isOpen tells the component when the modal should be open.
|
||||||
* @param {boolean} props.isOpen tells the component when the modal should be open.
|
* @param {React.Dispatch<React.SetStateAction<boolean>>} updateIsOpen used to close the modal.
|
||||||
* @param {React.Dispatch<React.SetStateAction<boolean>>} props.updateIsOpen used to close the modal.
|
* @param {date} date the date for which the sticker will be added or modified.
|
||||||
* @param {date} props.date the date for which the sticker will be added or modified.
|
|
||||||
* @param {React.Dispatch<React.SetStateAction<StickerVal>>} updateSticker the react state function to update the sticker.
|
* @param {React.Dispatch<React.SetStateAction<StickerVal>>} updateSticker the react state function to update the sticker.
|
||||||
* @param {StickerVal}currSticker the current sticker for the date.
|
* @param {StickerVal} currSticker the current sticker for the date.
|
||||||
|
* @param {number} step a numerical variable that represents the page the modal should be at.
|
||||||
|
* @param {React.Dispatch<React.SetStateAction<number>>} updateStep used to navigate the pages of the modal by updating the step the modal is on.
|
||||||
*/
|
*/
|
||||||
const AddSticker = ({
|
const AddSticker = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
updateIsOpen,
|
updateIsOpen,
|
||||||
date,
|
date,
|
||||||
updateSticker,
|
updateSticker,
|
||||||
currSticker
|
currSticker,
|
||||||
|
step,
|
||||||
|
updateStep
|
||||||
}: AddStickerProps): JSX.Element => {
|
}: AddStickerProps): JSX.Element => {
|
||||||
// TODO: Import the stickers array from the calender context.
|
// TODO: Import the stickers array from the calender context.
|
||||||
|
|
||||||
@@ -51,8 +56,6 @@ const AddSticker = ({
|
|||||||
|
|
||||||
const [selectedSticker, setSelectedSticker] = useState<StickerVal>(null);
|
const [selectedSticker, setSelectedSticker] = useState<StickerVal>(null);
|
||||||
|
|
||||||
const [step, setStep] = useState<number | null>(null);
|
|
||||||
|
|
||||||
const { addEditSticker } = useContext(StickersContext);
|
const { addEditSticker } = useContext(StickersContext);
|
||||||
|
|
||||||
const [modalVariant] = useState<"currDate" | "notCurrDate">(
|
const [modalVariant] = useState<"currDate" | "notCurrDate">(
|
||||||
@@ -63,16 +66,9 @@ const AddSticker = ({
|
|||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setSelectedSticker(null);
|
setSelectedSticker(null);
|
||||||
setStep(null);
|
|
||||||
updateIsOpen(false);
|
updateIsOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (step === null) {
|
|
||||||
setStep(0);
|
|
||||||
}
|
|
||||||
}, [step]);
|
|
||||||
|
|
||||||
// TODO: Validate that the provided sticker is not the current sticker. Throw an error if the same sticker is attempted.
|
// TODO: Validate that the provided sticker is not the current sticker. Throw an error if the same sticker is attempted.
|
||||||
const handleSubmit = (sticker) => {
|
const handleSubmit = (sticker) => {
|
||||||
const newSticker: Sticker = addEditSticker(date, sticker);
|
const newSticker: Sticker = addEditSticker(date, sticker);
|
||||||
@@ -164,7 +160,7 @@ const AddSticker = ({
|
|||||||
// isDisabled={
|
// isDisabled={
|
||||||
// selectedSticker === null || selectedSticker === currSticker
|
// selectedSticker === null || selectedSticker === currSticker
|
||||||
// }
|
// }
|
||||||
onClick={() => setStep(step + 1)}
|
onClick={() => updateStep(step + 1)}
|
||||||
>
|
>
|
||||||
{"Next"}
|
{"Next"}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -193,7 +189,7 @@ const AddSticker = ({
|
|||||||
justifyContent={"space-between"}
|
justifyContent={"space-between"}
|
||||||
alignContent={"center"}
|
alignContent={"center"}
|
||||||
>
|
>
|
||||||
<Button variant="primary" onClick={() => setStep(step - 1)}>
|
<Button variant="primary" onClick={() => updateStep(step - 1)}>
|
||||||
{"Previous"}
|
{"Previous"}
|
||||||
</Button>
|
</Button>
|
||||||
<HStack w="auto" h="auto" alignContent={"center"} spacing={6}>
|
<HStack w="auto" h="auto" alignContent={"center"} spacing={6}>
|
||||||
@@ -230,8 +226,6 @@ const AddSticker = ({
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
|
||||||
{step !== null && (
|
|
||||||
<Modal
|
<Modal
|
||||||
isCentered
|
isCentered
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
@@ -263,8 +257,6 @@ const AddSticker = ({
|
|||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
|
||||||
</Fragment>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user