import { Button, Modal, ModalOverlay, ModalContent, ModalHeader, ModalBody, ModalFooter, Heading, HStack, Text } from "@chakra-ui/react"; import React, { useState, useContext } from "react"; import { format, isSameDay } from "date-fns"; import { StickersContext } from "../../../contexts/StickerContext"; import StickerSelector from "./StickerSelector"; interface AddStickerProps { isOpen: boolean; updateIsOpen: React.Dispatch>; date: Date; updateSticker: React.Dispatch>; currSticker: StickerVal; step: number; updateStep: React.Dispatch>; selectedSticker: StickerVal; updateSelectedSticker: React.Dispatch>; } /** * Handles adding and modifying the stickers for the given month. * @param {boolean} isOpen tells the component when the modal should be open. * @param {React.Dispatch>} updateIsOpen used to close the modal. * @param {date} date the date for which the sticker will be added or modified. * @param {React.Dispatch>} updateSticker the react state function to update the sticker. * @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>} updateStep used to navigate the pages of the modal by updating the step the modal is on. */ const AddSticker = ({ isOpen, updateIsOpen, date, updateSticker, currSticker, step, updateStep, selectedSticker, updateSelectedSticker }: AddStickerProps): JSX.Element => { // TODO: Import the stickers array from the calender context. // TODO: Add a function that will add or update the sticker for the current date. /** * TODO: Add logic into the contents of the modal to show messages if the selected date is out of range. * Show a message when a date in the future is selected. * Show a message when a date before the current date is selected. */ const { addEditSticker } = useContext(StickersContext); const [modalVariant] = useState<"currDate" | "notCurrDate">( isSameDay(date, new Date()) ? "currDate" : "notCurrDate" ); // ! Step is not setting back to 0 when modal is closet. Try to move out of this component and take it in as an arg. const handleClose = () => { updateIsOpen(false); }; // TODO: Validate that the provided sticker is not the current sticker. Throw an error if the same sticker is attempted. const handleSubmit = (sticker) => { const newSticker: Sticker = addEditSticker(date, sticker); updateSticker(newSticker.sticker); handleClose(); }; // * Double check that the submit button is disabled if the selected sticker is the same as the current sticker. // TODO: Display the current sticker above the selection screen if a current sticker exists. // TODO: Trigger a warning if the date is in the past showing the sticker change. // ! DO NOT update the sticker state or trigger the edd/edit function until that new warning is accepted. const variants = { currDate: [ { header: `Which sticker did you earn for ${format(date, "LLL d, y")}?`, body: ( ), footer: ( ) } ], notCurrDate: [ { header: `Which sticker did you want to update for ${format( date, "LLL d, y" )}?`, body: ( ), footer: ( ) }, { header: `Are you sure you want to change the sticker for ${format( date, "M/d/y" )}?`, body: ( {"Filler"} ), footer: ( ) } ] }; return ( handleClose()} motionPreset="slideInBottom" scrollBehavior="inside" size={modalVariant === "currDate" ? "xl" : "2xl"} > {modalVariant && variants[modalVariant][step].header} {modalVariant && variants[modalVariant][step].body} {modalVariant && variants[modalVariant][step].footer} ); }; export default AddSticker;