Skip to content

Commit

Permalink
♻️ refactor: 카카오 지도 렌더링 함수 분리 #54
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMirror21 committed Oct 27, 2024
1 parent e789888 commit f58526b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 48 deletions.
30 changes: 1 addition & 29 deletions src/components/Document/write/EmployerInfoSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
LaborContractEmployerInfoProperty,
} from '@/types/api/document';
import { Address } from '@/types/api/users';
import { Map, MapMarker } from 'react-kakao-maps-sdk';
import { WorkDayTime } from '../../../types/api/document';
import {
arrayToString,
Expand All @@ -19,34 +18,7 @@ import {
workDayTimeToString,
} from '@/utils/document';
import Tag from '@/components/Common/Tag';

// 회사 주소지 지도로 렌더링하는 함수
const renderMap = (address: Address) => {
return (
<>
<div className="w-full self-stretch drop-shadow-[0_1px_2px_rgba(107,110,116,0.04)] rounded-xl flex flex-col items-center justify-start py-2.5 pr-3.5 pl-4">
<div className="w-full flex-1 relative">{address.address_name}</div>
</div>
<div className="w-full rounded-xl">
<Map
center={{
lat: Number(address.latitude),
lng: Number(address.longitude),
}}
style={{ width: '100%', height: '200px' }}
className="rounded-xl"
>
<MapMarker
position={{
lat: Number(address.latitude),
lng: Number(address.longitude),
}}
></MapMarker>
</Map>
</div>
</>
);
};
import { renderMap } from '@/utils/map';

const EmployerInfoSection = ({
employ,
Expand Down
19 changes: 0 additions & 19 deletions src/utils/map.ts

This file was deleted.

52 changes: 52 additions & 0 deletions src/utils/map.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Address } from '@/types/api/users';
import { Map, MapMarker } from 'react-kakao-maps-sdk';

/**
* 객체에서 지정된 속성들만 선택하여 새 객체를 반환하는 함수
* @param obj 원본 객체
* @param keys 선택할 속성들의 배열
* @returns 선택된 속성들로 이루어진 새 객체
*/
export const pick = <T extends object, K extends keyof T>(
obj: T,
keys: K[],
): Pick<T, K> =>
keys.reduce(
(result, key) => {
if (key in obj) {
result[key] = obj[key];
}
return result;
},
{} as Pick<T, K>,
);

// 입력된 주소지 지도로 렌더링하는 함수
export const renderMap = (address: Address) => {
return (
<>
<div className="w-full self-stretch drop-shadow-[0_1px_2px_rgba(107,110,116,0.04)] rounded-xl flex flex-col items-center justify-start py-2.5 pr-3.5 pl-4">
<div className="w-full flex-1 relative body-2">
{address.address_name}
</div>
</div>
<div className="w-full rounded-xl">
<Map
center={{
lat: Number(address.latitude),
lng: Number(address.longitude),
}}
style={{ width: '100%', height: '200px' }}
className="rounded-xl"
>
<MapMarker
position={{
lat: Number(address.latitude),
lng: Number(address.longitude),
}}
></MapMarker>
</Map>
</div>
</>
);
};

0 comments on commit f58526b

Please sign in to comment.