Skip to content

Commit

Permalink
feat: 메일 저장 버튼 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
seung365 committed Aug 7, 2024
1 parent 6fe4a1b commit 2a34d79
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/components/Mail/MailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
warningTextsBusiness,
warningTextsUniv,
} from './MailModalData';
import { useAuth } from '@/Provider/Auth';
import { usePostMail } from '@/api/hooks/usePostMail';

interface MailModalProps {
isOpen: boolean;
Expand All @@ -51,7 +53,11 @@ export const MailModal = ({ isOpen, onOpen, onClose }: MailModalProps) => {
const [isFocused, setIsFocused] = useState(false);
const [isHide, setIsHide] = useState(false);
const [firstInput, setFirstInput] = useState('');
const { isActive } = useMail();
const { isActive, handleMailResult, mailResult } = useMail();
const [noError, setNoError] = useState(false);
const { authInfo } = useAuth();

const { mutate: mailmutate } = usePostMail();

const currentcurrentInputNames =
isActive === 'univ' ? currentInputNames : currentInputNamesBusiness;
Expand Down Expand Up @@ -102,12 +108,18 @@ export const MailModal = ({ isOpen, onOpen, onClose }: MailModalProps) => {
setContent(data.content || '메일이 성공적으로 생성되었습니다.');
setIsSubmitted(true);
setIsLoading(false);
setNoError(true);
handleMailResult({
subject: data.title,
body: data.content,
});
},
onError: (error) => {
setTitle('메일 생성 실패');
setContent('메일 생성 중 오류가 발생했습니다.');
setIsSubmitted(true);
setIsLoading(false);
setNoError(false);
},
},
);
Expand Down Expand Up @@ -139,12 +151,19 @@ export const MailModal = ({ isOpen, onOpen, onClose }: MailModalProps) => {
setContent(data.content || '메일이 성공적으로 생성되었습니다.');
setIsSubmitted(true);
setIsLoading(false);
setNoError(true);

handleMailResult({
subject: data.title,
body: data.content,
});
},
onError: (error) => {
setTitle('메일 생성 실패');
setContent('메일 생성 중 오류가 발생했습니다.');
setIsSubmitted(true);
setIsLoading(false);
setNoError(false);
},
},
);
Expand Down Expand Up @@ -192,6 +211,14 @@ export const MailModal = ({ isOpen, onOpen, onClose }: MailModalProps) => {
}
};

const handlePutMail = () => {
if (authInfo) {
mailmutate({ ...mailResult });
} else {
alert('로그인 후 메일을 저장 할 수 있습니다.');
}
};

useEffect(() => {
setIsFocused(false);
setValue(currentcurrentInputNames[currentIndex], '', { shouldValidate: true });
Expand Down Expand Up @@ -337,6 +364,13 @@ export const MailModal = ({ isOpen, onOpen, onClose }: MailModalProps) => {
)}
</CustomModalFooter>
)}
{isSubmitted && noError && (
<ModalFooter>
<Button colorScheme="blue" onClick={handlePutMail}>
저장하기
</Button>
</ModalFooter>
)}
</CustomModalContent>
</CustomModal>
);
Expand Down

0 comments on commit 2a34d79

Please sign in to comment.