diff --git a/components/Profile/Edit/index.jsx b/components/Profile/Edit/index.jsx index 6f69703f..fbe9ea3a 100644 --- a/components/Profile/Edit/index.jsx +++ b/components/Profile/Edit/index.jsx @@ -1,4 +1,5 @@ -import React, { useMemo, useState, useEffect } from 'react'; +import React, { useMemo, useEffect } from 'react'; +import toast from 'react-hot-toast'; import { useRouter } from 'next/router'; import { useSelector } from 'react-redux'; import COUNTIES from '@/constants/countries.json'; @@ -28,14 +29,14 @@ import SEOConfig from '@/shared/components/SEO'; import useEditProfile from './useEditProfile'; import { + HomePageWrapper, + ContentWrapper, StyledGroup, StyledSelectWrapper, StyledSelectBox, StyledSelectText, StyledToggleWrapper, StyledToggleText, - HomePageWrapper, - ContentWrapper, StyledTitleWrap, StyledSection, StyledButtonGroup, @@ -48,12 +49,18 @@ function EditPage() { const { userState, onChangeHandler, onSubmit } = useEditProfile(); const user = useSelector((state) => state.user); - const [isLoadingSubmit, setIsLoadingSubmit] = useState(false); - useEffect(() => { if (user._id) { Object.entries(user).forEach(([key, value]) => { - onChangeHandler({ key, value }); + if (key !== 'contactList') { + onChangeHandler({ key, value }); + } else { + const { instagram, facebook, discord, line } = value; + onChangeHandler({ key: 'instagram', value: instagram || '' }); + onChangeHandler({ key: 'facebook', value: facebook || '' }); + onChangeHandler({ key: 'discord', value: discord || '' }); + onChangeHandler({ key: 'line', value: line || '' }); + } }); } else { router.push('/'); @@ -61,9 +68,8 @@ function EditPage() { }, [user]); const onUpdateUser = async (successCallback) => { - setIsLoadingSubmit(true); await onSubmit({ id: user._id, email: user.email }); - setIsLoadingSubmit(false); + toast.success('更新成功'); successCallback(); }; @@ -252,7 +258,6 @@ function EditPage() { {/* 聯絡方式 */} - {/* TODO: 新增 Social */} 聯絡方式 Instagram - + { + onChangeHandler({ + key: 'instagram', + value: event.target.value, + }); + }} + placeholder="請填寫ID" + sx={{ width: '100%' }} + /> Discord - + { + onChangeHandler({ + key: 'discord', + value: event.target.value, + }); + }} + placeholder="請填寫ID" + sx={{ width: '100%' }} + /> Line - + { + onChangeHandler({ + key: 'line', + value: event.target.value, + }); + }} + placeholder="請填寫ID" + sx={{ width: '100%' }} + /> Facebook - + { + onChangeHandler({ + key: 'facebook', + value: event.target.value, + }); + }} + placeholder="請填寫ID" + sx={{ width: '100%' }} + /> @@ -329,18 +374,17 @@ function EditPage() { }} /> - {/* TODO: 新增 TAG */} + {/* TODO: NEED TO FIXED */} 標籤 { onChangeHandler({ - tagList: event.target.value, - isMultiple: true, key: 'tagList', + value: event.target.value, }); }} /> diff --git a/components/Profile/Edit/useEditProfile.jsx b/components/Profile/Edit/useEditProfile.jsx index 91bd919b..e682236e 100644 --- a/components/Profile/Edit/useEditProfile.jsx +++ b/components/Profile/Edit/useEditProfile.jsx @@ -10,10 +10,12 @@ const initialState = { gender: '', roleList: [], wantToDoList: [], - // interestList: [], + instagram: '', + facebook: '', + discord: '', + line: '', educationStage: '-1', location: 'tw', - contactInformationList: [], tagList: [], selfIntroduction: '', share: '', @@ -47,8 +49,8 @@ const useEditProfile = () => { // TODO ErrorMap - const onChangeHandler = ({ key, value }) => { - stateDispatch({ key, value }); + const onChangeHandler = ({ key, value, isMultiple }) => { + stateDispatch({ key, value, isMultiple }); }; const onSubmit = async ({ id, email }) => { @@ -64,23 +66,31 @@ const useEditProfile = () => { share, isOpenLocation, isOpenProfile, - contactInformationList, tagList, selfIntroduction, + instagram, + facebook, + discord, + line, } = userState; const payload = { id, email, - contactInformationList, name, birthDay, gender, roleList, + contactList: { + instagram, + facebook, + discord, + line, + }, wantToDoList, educationStage, location, - tagList, + tagList: [tagList], // TODO: 要修改 selfIntroduction, share, isOpenLocation, diff --git a/components/Profile/UserCard/index.jsx b/components/Profile/UserCard/index.jsx index 290d8e56..9c4cfacb 100644 --- a/components/Profile/UserCard/index.jsx +++ b/components/Profile/UserCard/index.jsx @@ -190,6 +190,8 @@ function UserCard({ photoURL, userName, location, + contactList = {}, + updatedDate, }) { const router = useRouter(); @@ -230,30 +232,41 @@ function UserCard({ {!!tagList.length && + !!tagList[0] && tagList[0].split('、').map((tag) => )} -
  • - -

    Chien22

    -
  • -
  • - -

    ene_soew

    -
  • -
  • - -

    Chien12348888

    -
  • -
  • - -

    #Chien22

    -
  • + {!!contactList.instagram && ( +
  • + +

    {contactList.instagram}

    +
  • + )} + {!!contactList.facebook && ( +
  • + +

    {contactList.facebook}

    +
  • + )} + {!!contactList.line && ( +
  • + +

    {contactList.line}

    +
  • + )} + {!!contactList.discord && ( +
  • + +

    {contactList.discord}

    +
  • + )}
    - {moment(new Date() - 500 * 60 * 60).fromNow()} + {updatedDate + ? moment(updatedDate).fromNow() + : moment(new Date() - 500 * 60 * 60).fromNow()}