diff --git a/components/inbox-mail/CreateNewMailModal.tsx b/components/inbox-mail/CreateNewMailModal.tsx new file mode 100644 index 0000000..fb2cef2 --- /dev/null +++ b/components/inbox-mail/CreateNewMailModal.tsx @@ -0,0 +1,315 @@ +import BaseModal from "@/src/components/Common/ModalComponents/Modal"; +import ModalCreateFooter from "@/src/components/Common/ModalComponents/ModalCreateFooter"; +import { Dialog } from "@headlessui/react"; +import { useCallback, useEffect, 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"; +import { User } from "../inbox-mail/InboxMailView"; + + +interface CreateNewMailModalProps { + open: boolean; + setOpen: (open: boolean) => void; + refetchInboxMailOverview: () => void; + users: User[]; + threadId?: string; + isNewThread?: boolean; +}; + +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: 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 { state: selectedPeople, setState: setSelectedPeople, ref: selectedPeopleRef } = useRefState([]); + + + const cancelButtonRef = useRef(null); + + const initModal = useCallback(() => { + setSelectedPeople([]); + setSubject(''); + setContent(''); + setIncludeProject(false); + setIncludeChat(false); + setMarkAsImportant(false); + }, []); + + const onTransitionComplete = useCallback(initModal, []); + + const disabledSend = useMemo(() => { + return selectedPeople.length === 0 || subject.trim() === '' || content.trim() === ''; + }, [selectedPeople, subject, content]); + + const handleCreateMail = useCallback(() => { + const metaData = { + includeProject: includeProjectRef.current, + includeChat: includeChatRef.current + }; + + sendNewMail(selectedPeopleRef.current.map((user) => user.id), subjectRef.current, contentRef.current, markAsImportantRef.current, metaData, (result) => { + props.setOpen(false); + initModal(); + props.refetchInboxMailOverview(); + }, props.isNewThread ? undefined : props.threadId); + }, [props.threadId, props.isNewThread]); + + return ( + +
+
+
+ +
+
+ + {t("inboxMail.modalTitle")} + +
+ + +
+ +
+ setSubject(e.target.value)} + /> +
+
+
+ +
+