diff --git a/components/inbox-mail/CreateNewMailModal.tsx b/components/inbox-mail/CreateNewMailModal.tsx new file mode 100644 index 0000000..5585c30 --- /dev/null +++ b/components/inbox-mail/CreateNewMailModal.tsx @@ -0,0 +1,175 @@ +import BaseModal from "@/src/components/Common/ModalComponents/Modal"; +import ModalCreateFooter from "@/src/components/Common/ModalComponents/ModalCreateFooter"; +import { Dialog } from "@headlessui/react"; +import { useCallback, useMemo, useRef, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { useRouter } from "next/router"; +import { sendNewMail } from "./service-mail"; +import useRefState from "../../hooks/useRefState"; +import { InfoButton } from "../InfoButton"; +import { MemoIconMail } from "../kern-icons/icons"; + +type CreateNewMailModalProps = { + open: boolean; + setOpen: (open: boolean) => void; +}; + +export default function CreateNewMailModal(props: CreateNewMailModalProps) { + const router = useRouter(); + const { t } = useTranslation('projectOverview'); + const projectId = router.query.projectId as string; + const chatId = router.query.chatId as string; + const { state: sendTo, setState: setSendTo, ref: sendToRef } = useRefState([]); + const { state: subject, setState: setSubject, ref: subjectRef } = useRefState(''); + const { state: content, setState: setContent, ref: contentRef } = useRefState(''); + const { state: includeProject, setState: setIncludeProject, ref: includeProjectRef } = useRefState(false); + const { state: includeChat, setState: setIncludeChat, ref: includeChatRef } = useRefState(false); + const { state: markAsImportant, setState: setMarkAsImportant, ref: markAsImportantRef } = useRefState(false); + const [availableEmails, setAvailableEmails] = useState(['test@gmail.com', 'test1@gmail.com']); + const [selectedEmails, setSelectedEmails] = useState([]); + + const cancelButtonRef = useRef(null); + + const initModal = useCallback(() => { + setSendTo([]); + setSubject(''); + setContent(''); + setIncludeProject(false); + setIncludeChat(false); + setMarkAsImportant(false); + }, []); + + const onTransitionComplete = useCallback(initModal, []); + + const disabledSend = useMemo(() => { + return sendTo.length === 0 || subject.trim() === '' || content.trim() === ''; + }, [sendTo, subject, content]); + + const handleCreateMail = useCallback(() => { + const metaData = { + includeProject: includeProjectRef.current, + includeChat: includeChatRef.current + }; + sendNewMail(sendToRef.current, subjectRef.current, contentRef.current, markAsImportantRef.current, metaData, (result) => { + props.setOpen(false); + initModal(); + }); + }, []); + + return ( + +
+
+
+ +
+
+ + {t("inboxMail.modalTitle")} + +
+
+ +
+ setSendTo([e.target.value])} + /> +
+
+
+ +
+ setSubject(e.target.value)} + /> +
+
+
+ +
+