From c26c374ade834d1c6f4d4d3fc688a322637ac849 Mon Sep 17 00:00:00 2001 From: Johnson Mao <86179381+JohnsonMao@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:16:25 +0800 Subject: [PATCH] fix: send email to group own (#60) * fix: vercel auto deploy config * fix: send email to group own --- components/Group/detail/Contact/Feedback.jsx | 3 +- components/Group/detail/Contact/index.jsx | 54 +++++++++++--------- next.config.js | 20 +++++--- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/components/Group/detail/Contact/Feedback.jsx b/components/Group/detail/Contact/Feedback.jsx index 462e68a7..b4f8da99 100644 --- a/components/Group/detail/Contact/Feedback.jsx +++ b/components/Group/detail/Contact/Feedback.jsx @@ -31,8 +31,7 @@ function Feedback({ type, onClose }) { error: { imgSrc: contractErrorImg.src, imgAlt: 'error cover', - // title: '哎呀!有不明錯誤', - title: '目前功能還在測試階段,敬請期待!', + title: '哎呀!有不明錯誤', buttonText: '再試一次', }, }; diff --git a/components/Group/detail/Contact/index.jsx b/components/Group/detail/Contact/index.jsx index 190a63a8..677da118 100644 --- a/components/Group/detail/Contact/index.jsx +++ b/components/Group/detail/Contact/index.jsx @@ -15,11 +15,14 @@ import { useMediaQuery, } from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; -import { BASE_URL } from '@/constants/common'; import { ROLE } from '@/constants/member'; import chatSvg from '@/public/assets/icons/chat.svg'; +import useMutation from '@/hooks/useMutation'; +import { mapToTable } from '@/utils/helper'; import Feedback from './Feedback'; +const ROLELIST = mapToTable(ROLE); + const StyledTitle = styled.label` display: block; color: var(--black-white-gray-dark, #293a3d); @@ -71,30 +74,35 @@ function ContactButton({ setMessage(''); setContact(''); }; + const { mutate } = useMutation(`/email`, { + method: 'POST', + onSuccess: () => { + handleClose(); + setFeedback('success'); + }, + onError: () => { + handleClose(); + setFeedback('error'); + }, + }); const handleSubmit = () => { - fetch(`${BASE_URL}/email`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - ...user, - subject: '【島島阿學】點開 Email,認識新夥伴', - title: '你發起的揪團有人來信!', - to: user.email, - text: message, - information: [me.email, contact], - }), - }) - .then(() => { - handleClose(); - setFeedback('success'); - }) - .catch(() => { - handleClose(); - setFeedback('error'); - }); + mutate({ + userId: me._id, + url: window.location.origin, + name: me.name, + roleList: + me.roleList.length > 0 + ? me.roleList.map((roleKey) => ROLELIST[roleKey]) + : [''], + photoUrl: me.photoURL, + from: me.email, + to: user.email, + subject: '【島島阿學】點開 Email,認識新夥伴', + title: '你發起的揪團有人來信!', + text: message, + information: [me.email, contact], + }); }; useEffect(() => { diff --git a/next.config.js b/next.config.js index 46850e91..6300a18f 100644 --- a/next.config.js +++ b/next.config.js @@ -1,3 +1,5 @@ +const isDev = process.env.NODE_ENV === 'development'; + const withPWA = require('next-pwa')({ dest: 'public', }); @@ -10,14 +12,16 @@ module.exports = withPWA({ env: { HOSTNAME: 'https://www.daoedu.tw', }, - async rewrites() { - return [ - { - source: '/dev-proxy-api/:path*', - destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`, - }, - ]; - }, + ...(isDev ? { + async rewrites() { + return [ + { + source: '/dev-proxy-api/:path*', + destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`, + }, + ]; + }, + } : {}) // async redirects() { // return [ // {