Skip to content

Commit

Permalink
Merge pull request #34 from daodaoedu/feature/edit_locations
Browse files Browse the repository at this point in the history
feat: Add country/city/district field in Location profile/edit, Modif…
  • Loading branch information
hsuifang authored Jan 30, 2024
2 parents 1cb36b1 + 174c8c8 commit fa0c22b
Show file tree
Hide file tree
Showing 5 changed files with 1,711 additions and 17 deletions.
9 changes: 7 additions & 2 deletions components/Partner/PartnerList/PartnerCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function PartnerCard({

const role = roleList.length > 0 && ROLELIST[roleList[0]];
const edu = educationStage && EDUCATION_STEP_TABLE[educationStage];
const locations = location && location.split('@');

return (
<StyledCard>
Expand All @@ -66,10 +67,14 @@ function PartnerCard({
<FlexSBAlignCenter mt="12px">
<StyledTypoCaption>
<FlexAlignCenter>
{location && (
{locations && (
<>
<LocationOnOutlinedIcon sx={{ marginRight: '10px' }} />
{location}
{location
? location.length >= 2
? locations.join('').replace('台灣', '')
: locations.join('')
: '-'}
</>
)}
</FlexAlignCenter>
Expand Down
80 changes: 70 additions & 10 deletions components/Profile/Edit/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import toast from 'react-hot-toast';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useRouter } from 'next/router';
import { useSelector } from 'react-redux';
import { AREAS } from '@/constants/areas';
import { AREAS, TAIWAN_DISTRICT } from '@/constants/areas';
import COUNTIES from '@/constants/countries.json';

import {
GENDER,
ROLE,
Expand Down Expand Up @@ -56,14 +58,20 @@ function EditPage() {
useEffect(() => {
if (user._id) {
Object.entries(user).forEach(([key, value]) => {
if (key !== 'contactList') {
onChangeHandler({ key, value });
} else {
if (key === 'contactList') {
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 if (key === 'location') {
onChangeHandler({ key, value });
const [country, city, district] = value.split('@');
onChangeHandler({ key: 'country', value: country || null });
onChangeHandler({ key: 'city', value: city || null });
onChangeHandler({ key: 'district', value: district || null });
} else {
onChangeHandler({ key, value });
}
});
} else {
Expand Down Expand Up @@ -238,12 +246,12 @@ function EditPage() {
<StyledGroup>
<Typography>居住地</Typography>
<Select
labelId="location"
id="location"
value={userState.location}
labelId="country"
id="country"
value={userState.country}
onChange={(event) => {
onChangeHandler({
key: 'location',
key: 'country',
value: event.target.value,
});
}}
Expand All @@ -252,12 +260,64 @@ function EditPage() {
<MenuItem disabled value="-1">
<em>請選擇居住地</em>
</MenuItem>
{AREAS.map(({ name, label }) => (
<MenuItem key={label} value={label}>
{COUNTIES.map(({ name, alpha2 }) => (
<MenuItem key={alpha2} value={name}>
{name}
</MenuItem>
))}
</Select>
{(userState.country === '台灣' || userState.country === 'tw') && (
<Grid container columnSpacing={1}>
<Grid item xs="12" sm="6">
<Select
labelId="country"
id="country"
value={userState.city}
onChange={(event) => {
onChangeHandler({
key: 'city',
value: event.target.value,
});
}}
sx={{ width: '100%' }}
>
<MenuItem disabled value="-1">
<em>縣市</em>
</MenuItem>
{TAIWAN_DISTRICT.map(({ name }) => (
<MenuItem key={name} value={name}>
{name}
</MenuItem>
))}
</Select>
</Grid>
<Grid item xs="12" sm="6">
<Select
labelId="district"
id="district"
value={userState.district}
onChange={(event) => {
onChangeHandler({
key: 'district',
value: event.target.value,
});
}}
sx={{ width: '100%' }}
>
<MenuItem disabled value="-1">
<em>鄉鎮市區</em>
</MenuItem>
{TAIWAN_DISTRICT.find(
({ name }) => name === userState.city,
)?.districts.map(({ name, zip }) => (
<MenuItem key={zip} value={name}>
{name}
</MenuItem>
))}
</Select>
</Grid>
</Grid>
)}
</StyledGroup>
</StyledSection>

Expand Down
13 changes: 9 additions & 4 deletions components/Profile/Edit/useEditProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ const initialState = {
discord: '',
line: '',
educationStage: '-1',
location: 'tw',
location: '台灣',
tagList: [],
selfIntroduction: '',
share: '',
isOpenLocation: false,
isOpenProfile: false,
isLoadingSubmit: false,
country: '',
city: '',
district: '',
};

const userReducer = (state, payload) => {
Expand Down Expand Up @@ -61,7 +64,6 @@ const useEditProfile = () => {
gender,
roleList,
educationStage,
location,
wantToDoList,
share,
isOpenLocation,
Expand All @@ -72,6 +74,9 @@ const useEditProfile = () => {
facebook,
discord,
line,
country,
city,
district,
} = userState;

const payload = {
Expand All @@ -89,8 +94,8 @@ const useEditProfile = () => {
},
wantToDoList,
educationStage,
location,
tagList, // TODO: 要修改
location: `${country}@${city}@${district}`,
tagList,
selfIntroduction,
share,
isOpenLocation,
Expand Down
6 changes: 5 additions & 1 deletion components/Profile/UserCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ function UserCard({

<StyledProfileLocation>
<LocationOnOutlinedIcon sx={{ marginRight: '10px' }} />{' '}
{location || '-'}
{location
? location.split('@').length >= 2
? location.split('@').join('').replace('台灣', '')
: location.split('@').join('')
: '-'}
</StyledProfileLocation>
</Box>
</StyledProfileBaseInfo>
Expand Down
Loading

0 comments on commit fa0c22b

Please sign in to comment.