Skip to content

Commit

Permalink
Merge pull request #193 from kakao-tech-campus-2nd-step3/Refactor/issโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆue-#192

[๋ฆฌํŒฉํ† ๋ง] ์ƒํƒœ๊ด€๋ฆฌ์™€ ui ๋ถ„๋ฆฌ (custom hook)
  • Loading branch information
Diwoni authored Nov 12, 2024
2 parents 3ef36c0 + dd43cae commit 54cb46a
Show file tree
Hide file tree
Showing 69 changed files with 522 additions and 335 deletions.
1 change: 0 additions & 1 deletion src/pages/guard/guide-line/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export { getSeniorAllGuidelines } from './view-senior-all-guideline.api';
export { modifyGuideline } from './modify-guideline.api';
export { addGuideline } from './add-guideline.api';
export { deleteGuideline } from './delete-guideline.api';
export * from './hooks';
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { fetchInstance } from '@/shared/api/instance';

export type SeniorAllGuideLineResponse = {
export type SeniorAllGuideLineResponse = SeniorGuideLineData[];

export type SeniorGuideLineData = {
id: number;
type: string;
title: string;
content: string;
}[];
};

export type SeniorAllGuideLineRequest = {
seniorId: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useForm } from 'react-hook-form';

import { useAddGuideline } from '../../hooks';
import GuidelineFormField, { GuidelineValues } from './GuideFormField';
import { useAddGuideline } from '@/pages/guard';
import { BasicButton } from '@/shared';
import { Box, Flex } from '@chakra-ui/react';
import styled from '@emotion/styled';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addGuideline, AddGuidelineRequest } from '../add-guideline.api';
import { addGuideline, AddGuidelineRequest } from '../api/add-guideline.api';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

export const useAddGuideline = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deleteGuideline } from '../delete-guideline.api';
import { deleteGuideline } from '../api';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

export const useDeleteGuideline = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
getSeniorAllGuidelines,
getSeniorAllGuidelinesQueryKey,
SeniorAllGuideLineResponse,
} from '../view-senior-all-guideline.api';
} from '../api/view-senior-all-guideline.api';
import { useQuery } from '@tanstack/react-query';

export const useGetSeniorAllGuidelines = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
getViewSpecificGuideline,
getViewSpecificGuidelineQueryKey,
ViewSpecificGuidelineResponse,
} from '../view-specific-guideline.api';
} from '../api/view-specific-guideline.api';
import { useQuery } from '@tanstack/react-query';

export const useGetViewSpecificGuideline = (guidelineId: number) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { ModifyGuidelineRequest } from '../modify-guideline.api';
import { ModifyGuidelineRequest } from '../api/modify-guideline.api';
import { UseMutationResult } from '@tanstack/react-query';

type GuidelineInfo = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
modifyGuideline,
ModifyGuidelineRequest,
} from '../modify-guideline.api';
} from '../api/modify-guideline.api';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

export const useModifyGuideline = (
Expand Down
3 changes: 2 additions & 1 deletion src/pages/guard/guide-line/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { GuideLinePage } from './GuideLinePage';
export { GuideLinePage } from './ui';

export * from './api';
export * from './components';
export * from './data';
export * from './hooks';
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useParams } from 'react-router-dom';

import { useGetSeniorAllGuidelines } from './api';
import { GuideLineInfo, GuidelineRegisterBox } from './components';
import { SeniorGuideLineData } from '../api/view-senior-all-guideline.api';
import { GuideLineInfo, GuidelineRegisterBox } from '../components';
import { useGetSeniorAllGuidelines } from '../hooks';
import { PageLayout } from '@/shared';
import { Box, Flex, Text } from '@chakra-ui/react';

Expand All @@ -13,19 +14,10 @@ export type GuideLineDetailParams = {
export const GuideLinePage = () => {
const { seniorId, guidelineType } = useParams<GuideLineDetailParams>();

const {
data: guidelineData,
isLoading,
isError,
refetch,
} = useGetSeniorAllGuidelines(Number(seniorId), String(guidelineType));
if (isLoading) {
return <div>Loading...</div>;
}

if (isError) {
return <div>Error</div>;
}
const { data: guidelineData, refetch } = useGetSeniorAllGuidelines(
Number(seniorId),
String(guidelineType)
);

return (
<PageLayout>
Expand Down Expand Up @@ -64,7 +56,7 @@ export const GuideLinePage = () => {
</Text>
</Box>
<Flex w='full' flexDir='column' gap='var(--space-sm)'>
{guidelineData?.map((guideline) => (
{guidelineData?.map((guideline: SeniorGuideLineData) => (
<GuideLineInfo
key={guideline.id}
refetch={refetch}
Expand Down
1 change: 1 addition & 0 deletions src/pages/guard/guide-line/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { GuideLinePage } from './GuideLinePage';
1 change: 0 additions & 1 deletion src/pages/guard/mypage/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export {
export { getAllSeniorInfo } from './all-senior-info.api';

export * from './types';
export * from './hooks';
101 changes: 39 additions & 62 deletions src/pages/guard/mypage/components/profile-box/GuardProfileBox.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

import { useGetGuardInformation, useModifyGuardInformation } from '../../api';
import { RouterPath } from '@/app/routes';
import { useGetGuardInformation, useModifyGuardInformation } from '../../hooks';
import { useGuardProfile } from '../../hooks/useGuardProfile';
import { IconArrow } from '@/pages/assets';
import {
Logout,
formatPhoneNumber,
BasicButton,
parsePhoneNumber,
} from '@/shared';
import { Logout, formatPhoneNumber, BasicButton } from '@/shared';
import { Box, Text, Flex, Input } from '@chakra-ui/react';
import styled from '@emotion/styled';

const GuardProfileBox = () => {
const [name, setName] = useState('');
const [phoneNumber, setPhoneNumber] = useState('');
const [isEditing, setIsEditing] = useState(false);

const { data: guardInfo, refetch } = useGetGuardInformation();
const modifyGuardInfoMutation = useModifyGuardInformation();
const navigate = useNavigate();

useEffect(() => {
if (isEditing) {
setName(guardInfo?.name || '');
setPhoneNumber(guardInfo?.phoneNumber || '');
}
}, [isEditing, guardInfo]);

const handleSaveClick = () => {
const modifiedSinittoInfo = {
name: name,
phoneNumber: parsePhoneNumber(phoneNumber),
};
modifyGuardInfoMutation.mutate(modifiedSinittoInfo, {
onSuccess: () => {
setIsEditing(false);
refetch();
},
});
};
const {
name,
phoneNumber,
isEditing,
setName,
setPhoneNumber,
setIsEditing,
handleSaveClick,
handleServiceManualClick,
handleSeniorManagementClick,
handleServiceHistoryClick,
} = useGuardProfile({
guardInfo,
modifyGuardInfoMutation,
refetch,
});

return (
<>
Expand All @@ -56,22 +40,28 @@ const GuardProfileBox = () => {
</Flex>
<Logout />
</Flex>
<ServiceManualBox onClick={() => navigate(RouterPath.SERVICE_MANUAL)}>
<ServiceManualBox onClick={handleServiceManualClick}>
<Text
fontSize='var(--font-size-lg)'
fontWeight={600}
mr='var(--space-xs)'
>
โ“˜
</Text>{' '}
</Text>
<Text fontWeight={600} mt='2px' mr='var(--space-sm)'>
์„œ๋น„์Šค ์ด์šฉ ๋ฐฉ๋ฒ• ํ•œ๋ฒˆ์— ์ดํ•ดํ•˜๊ธฐ!
</Text>
<IconArrow fill='var(--color-gray)' type='solid' />
</ServiceManualBox>
</Flex>

<GuardProfileBoxLayout>
<Flex
flexDir='column'
w='100%'
h='auto'
border='2px solid var(--color-white-gray)'
borderRadius='5px'
>
<Flex
w='full'
flexDir='column'
Expand Down Expand Up @@ -133,41 +123,28 @@ const GuardProfileBox = () => {
)}
</Flex>

<BottomContainer>
<ButtonBox onClick={() => navigate(RouterPath.SENIOR_REGISTER)}>
<Flex
alignItems='center'
justifyContent='space-between'
borderTop='2px solid var(--color-white-gray)'
padding='var(--space-sm) var(--space-xs)'
gap='var(--space-xs)'
>
<ButtonBox onClick={handleSeniorManagementClick}>
๋‚ด ์‹œ๋‹ˆ์–ด ๊ด€๋ฆฌ
</ButtonBox>
<DivideLine />
<ButtonBox onClick={() => navigate(RouterPath.SERVICE_HISTORY)}>
<ButtonBox onClick={handleServiceHistoryClick}>
์„œ๋น„์Šค ์ด์šฉ ํ˜„ํ™ฉ
</ButtonBox>
</BottomContainer>
</GuardProfileBoxLayout>
</Flex>
</Flex>
</>
);
};

export default GuardProfileBox;

const GuardProfileBoxLayout = styled(Box)`
display: flex;
flex-direction: column;
width: 100%;
height: auto;
border: 2px solid var(--color-white-gray);
border-radius: 5px;
`;

const BottomContainer = styled(Box)`
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
border-top: 2px solid var(--color-white-gray);
padding: var(--space-sm) var(--space-xs);
gap: var(--space-xs);
`;

const DivideLine = styled.div`
width: 2px;
height: 50px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { useGetGuardInformation } from './useGetGuardInformation';
export { useGetAllSeniorInfo } from './useGetAllSeniorInfo';
export { useModifyGuardInformation } from './useModifyGuardInfo';
export { useGuardProfile } from './useGuardProfile';
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { allSeniorInfoPath, getAllSeniorInfo } from '../all-senior-info.api';
import { AllSeniorInfoResponse } from '../types';
import { AllSeniorInfoResponse } from '../api';
import {
allSeniorInfoPath,
getAllSeniorInfo,
} from '../api/all-senior-info.api';
import { useQuery } from '@tanstack/react-query';

export const allSeniorInfoQueryKey = [allSeniorInfoPath()];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
getGuardInformation,
guardInformationPath,
} from '../guard-information.api';
import { GuardInformationResponse } from '../types';
import { GuardInformationResponse, getGuardInformation } from '../api';
import { guardInformationPath } from '../api/guard-information.api';
import { useQuery } from '@tanstack/react-query';

export const getGuardInformationQueryKey = [guardInformationPath()];
Expand Down
Loading

0 comments on commit 54cb46a

Please sign in to comment.