diff --git a/components/Group/Form/useGroupForm.jsx b/components/Group/Form/useGroupForm.jsx index 96394719..cf5134fc 100644 --- a/components/Group/Form/useGroupForm.jsx +++ b/components/Group/Form/useGroupForm.jsx @@ -143,7 +143,13 @@ export default function useGroupForm() { }; useEffect(() => { - if (notLogin) openLoginWindow(); + let timer; + if (notLogin) { + timer = setTimeout(() => { + openLoginWindow(); + }, 100); + } + return () => clearTimeout(timer); }, [notLogin]); return { diff --git a/components/Group/detail/Contact/ContactPopup.jsx b/components/Group/detail/Contact/ContactPopup.jsx new file mode 100644 index 00000000..491062db --- /dev/null +++ b/components/Group/detail/Contact/ContactPopup.jsx @@ -0,0 +1,224 @@ +import { useId, useState } from 'react'; +import styled from '@emotion/styled'; +import { + Avatar, + Box, + Button, + Dialog, + DialogTitle, + IconButton, + Typography, + TextareaAutosize, + useMediaQuery, +} from '@mui/material'; +import CloseIcon from '@mui/icons-material/Close'; +import { ROLE } from '@/constants/member'; +import TransitionSlide from './TransitionSlide'; + +const StyledTitle = styled.label` + display: block; + color: var(--black-white-gray-dark, #293a3d); + font-size: 16px; + font-style: normal; + font-weight: 500; + line-height: 140%; /* 22.4px */ + margin-bottom: 11px; +`; +const StyledTextArea = styled(TextareaAutosize)` + display: block; + padding: 12px 16px; + background: var(--black-white-white, #fff); + border-radius: 8px; + border: 1px solid var(--black-white-gray-very-light, #dbdbdb); + width: 100%; + min-height: 128px; +`; + +function ContactPopup({ + open, + user, + label, + description, + descriptionPlaceholder, + isLoading, + onClose, + onSubmit, +}) { + const isMobileScreen = useMediaQuery('(max-width: 560px)'); + const [message, setMessage] = useState(''); + const [contact, setContact] = useState(''); + const id = useId(); + const titleId = `modal-title-${id}`; + const descriptionId = `modal-description-${id}`; + const messageId = `message-${id}`; + const contactId = `contact-${id}`; + const role = + ROLE.find(({ key }) => user?.roleList?.includes(key))?.label || '暫無資料'; + + const handleClose = () => { + setMessage(''); + setContact(''); + onClose(); + }; + + const handleSubmit = () => { + onSubmit({ message, contact }); + }; + + return ( + + + {label} + + + + + + + +
+ + {user?.name || '名稱'} + + + {role} + +
+
+ +
+ + {description} + + setMessage(e.target.value)} + placeholder={descriptionPlaceholder} + /> +
+ +
+ 聯絡資訊 + setContact(e.target.value)} + placeholder="寫下您的聯絡資訊,初次聯繫建議提供「想公開的社群媒體帳號、email」即可。" + /> +
+ + + + + +
+
+ ); +} + +export default ContactPopup; diff --git a/components/Group/detail/Contact/Feedback.jsx b/components/Group/detail/Contact/FeedbackPopup.jsx similarity index 90% rename from components/Group/detail/Contact/Feedback.jsx rename to components/Group/detail/Contact/FeedbackPopup.jsx index b4f8da99..c8282c33 100644 --- a/components/Group/detail/Contact/Feedback.jsx +++ b/components/Group/detail/Contact/FeedbackPopup.jsx @@ -1,21 +1,17 @@ -import { useId, forwardRef } from 'react'; +import { useId } from 'react'; import { Box, Button, Dialog, DialogTitle, - Slide, Typography, useMediaQuery, } from '@mui/material'; import contractDoneImg from '@/public/assets/contactdone.png'; import contractErrorImg from '@/public/assets/contacterror.png'; +import TransitionSlide from './TransitionSlide'; -const Transition = forwardRef((props, ref) => { - return ; -}); - -function Feedback({ type, onClose }) { +function FeedbackPopup({ type, onClose }) { const id = useId(); const isMobileScreen = useMediaQuery('(max-width: 560px)'); const titleId = `modal-title-${id}`; @@ -46,7 +42,7 @@ function Feedback({ type, onClose }) { onClose={onClose} aria-labelledby={titleId} aria-describedby={descriptionId} - TransitionComponent={Transition} + TransitionComponent={TransitionSlide} sx={{ '.MuiPaper-root': { marginTop: isMobileScreen ? '84px' : undefined, @@ -78,6 +74,7 @@ function Feedback({ type, onClose }) { {content.title} + + 請先登入或註冊 + + + 登入後才可以使用聯繫夥伴功能唷! + + + 登入 + + + + + + + ); +} + +export default LoginPopup; diff --git a/components/Group/detail/Contact/TransitionSlide.jsx b/components/Group/detail/Contact/TransitionSlide.jsx new file mode 100644 index 00000000..c596c872 --- /dev/null +++ b/components/Group/detail/Contact/TransitionSlide.jsx @@ -0,0 +1,8 @@ +import { forwardRef } from 'react'; +import { Slide } from '@mui/material'; + +const TransitionSlide = forwardRef((props, ref) => { + return ; +}); + +export default TransitionSlide; diff --git a/components/Group/detail/Contact/index.jsx b/components/Group/detail/Contact/index.jsx index 5d8934ab..cdd778b5 100644 --- a/components/Group/detail/Contact/index.jsx +++ b/components/Group/detail/Contact/index.jsx @@ -1,28 +1,16 @@ -import { useId, useState, forwardRef, useEffect } from 'react'; -import { useRouter } from 'next/router'; +import { useState } from 'react'; import { useSelector } from 'react-redux'; import styled from '@emotion/styled'; -import { - Avatar, - Box, - Button, - Dialog, - DialogTitle, - IconButton, - Slide, - Typography, - TextareaAutosize, - useMediaQuery, -} from '@mui/material'; -import CloseIcon from '@mui/icons-material/Close'; +import { Button } from '@mui/material'; import { ROLE } from '@/constants/member'; import chatSvg from '@/public/assets/icons/chat.svg'; import useMutation from '@/hooks/useMutation'; import { mapToTable } from '@/utils/helper'; -import openLoginWindow from '@/utils/openLoginWindow'; -import Feedback from './Feedback'; +import ContactPopup from './ContactPopup'; +import FeedbackPopup from './FeedbackPopup'; +import LoginPopup from './LoginPopup'; -const ROLELIST = mapToTable(ROLE); +const ROLE_LIST = mapToTable(ROLE); const StyledButton = styled(Button)` padding: 8px 36px; @@ -37,41 +25,6 @@ const StyledButton = styled(Button)` opacity: 0.3; } `; -const StyledTitle = styled.label` - display: block; - color: var(--black-white-gray-dark, #293a3d); - font-size: 16px; - font-style: normal; - font-weight: 500; - line-height: 140%; /* 22.4px */ - margin-bottom: 11px; -`; -const StyledTextArea = styled(TextareaAutosize)` - display: block; - padding: 12px 16px; - background: var(--black-white-white, #fff); - border-radius: 8px; - border: 1px solid var(--black-white-gray-very-light, #dbdbdb); - width: 100%; - min-height: 128px; -`; -const StyledText = styled.div` - margin-top: 6px; - margin-left: 6px; - display: block; - color: black; - font-size: 12px; -`; -const StyledLink = styled.span` - padding: 0 2px; - color: #16b9b3; - text-decoration: underline; - cursor: pointer; -`; - -const Transition = forwardRef((props, ref) => { - return ; -}); function ContactButton({ user, @@ -81,26 +34,13 @@ function ContactButton({ descriptionPlaceholder, isLoading, }) { - const id = useId(); - const router = useRouter(); const me = useSelector((state) => state.user); const [open, setOpen] = useState(false); - const [message, setMessage] = useState(''); - const [contact, setContact] = useState(''); const [feedback, setFeedback] = useState(''); - const isMobileScreen = useMediaQuery('(max-width: 560px)'); - const titleId = `modal-title-${id}`; - const descriptionId = `modal-description-${id}`; - const messageId = `message-${id}`; - const contactId = `contact-${id}`; const isLogin = !!me?._id; - const role = - ROLE.find(({ key }) => user?.roleList?.includes(key))?.label || '暫無資料'; const handleClose = () => { setOpen(false); - setMessage(''); - setContact(''); }; const { mutate } = useMutation(`/email`, { method: 'POST', @@ -114,14 +54,14 @@ function ContactButton({ }, }); - const handleSubmit = () => { + const handleSubmit = ({ message, contact }) => { mutate({ userId: me._id, url: window.location.origin, name: me.name, roleList: me.roleList.length > 0 - ? me.roleList.map((roleKey) => ROLELIST[roleKey]) + ? me.roleList.map((roleKey) => ROLE_LIST[roleKey]) : [''], photoUrl: me.photoURL, from: me.email, @@ -134,17 +74,9 @@ function ContactButton({ }); }; - useEffect(() => { - if (!me?._id && open) router.push('/login'); - }, [me?._id, open, router]); - return (
- setOpen(true)} - > + setOpen(true)}> contact icon {label} - {!isLogin && ( - - router.push('/login')}>註冊或 - openLoginWindow()}>登入 - 即可聯繫主揪! - + {isLogin ? ( + + ) : ( + setOpen(false)} /> )} - - - {label} - - - - - - - -
- - {user?.name || '名稱'} - - - {role} - -
-
- -
- - {description} - - setMessage(e.target.value)} - placeholder={descriptionPlaceholder} - /> -
- -
- 聯絡資訊 - setContact(e.target.value)} - placeholder="寫下您的聯絡資訊,初次聯繫建議提供「想公開的社群媒體帳號、email」即可。" - /> -
- - - - - -
-
- setFeedback('')} /> + setFeedback('')} />
); } diff --git a/components/Group/detail/index.jsx b/components/Group/detail/index.jsx index 8f68da74..d333317e 100644 --- a/components/Group/detail/index.jsx +++ b/components/Group/detail/index.jsx @@ -22,7 +22,7 @@ import ShareButtonGroup from './ShareButtonGroup'; function GroupDetail({ id, source, isLoading }) { const router = useRouter(); const me = useSelector((state) => state.user); - const isMyGroup = source?.userId === me?._id; + const isMyGroup = source?.userId === me?._id && !!me?._id; return ( diff --git a/pages/login/index.jsx b/pages/login/index.jsx index 45f8e3cd..d272a23b 100644 --- a/pages/login/index.jsx +++ b/pages/login/index.jsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo } from 'react'; import styled from '@emotion/styled'; import { useRouter } from 'next/router'; import Script from 'next/script'; @@ -9,7 +9,7 @@ import Navigation from '@/shared/components/Navigation_v2'; import Footer from '@/shared/components/Footer_v2'; import { BASE_URL } from '@/constants/common'; import openLoginWindow from '@/utils/openLoginWindow'; -// import sendDataToChromeExtension from '../../utils/sendDataToChromeExtension'; +import { useSelector } from 'react-redux'; const HomePageWrapper = styled.div` --section-height: calc(100vh - 80px); @@ -40,6 +40,7 @@ const ContentWrapper = styled.div` const LoginPage = () => { const LOGIN_PATH = `${BASE_URL}/auth/google`; const router = useRouter(); + const me = useSelector((state) => state.user); const SEOData = useMemo( () => ({ @@ -55,6 +56,12 @@ const LoginPage = () => { [router?.asPath], ); + useEffect(() => { + if (me?._id) { + router.push('/'); + } + }, []); + return (