Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | import { usePatchModifyMapTagMutation } from '@lib/api/mutations';
import { useGetAdventuresQuery, useGetMapTagQuery } from '@lib/api/queries';
import GoogleMapComponent from '@lib/components/GoogleMap';
import {
CreateMapTagRequestDto,
CreateMapTagRequestDtoMapTypeEnum
} from '@uniquegood/realworld-adventure-interface';
import { Form, Input, InputNumber, Modal, ModalProps, Select, Switch, message } from 'antd';
import React from 'react';
import styled from 'styled-components';
type ModifyMapTagModalProps = {
modalData: ModalProps;
closeModal: () => unknown;
mapTagId: string;
};
interface ModifyFormData extends Omit<CreateMapTagRequestDto, 'iconImageUrl'> {
iconImageUrl: {
file: File;
fileList: (File & { uid: string; url: string; originFileObj: File })[];
};
}
export default function ModifyMapTagModal({
modalData,
closeModal,
mapTagId
}: ModifyMapTagModalProps) {
const [form] = Form.useForm();
const { data: adventures, isLoading } = useGetAdventuresQuery();
const { data: mapTag } = useGetMapTagQuery({ mapTagId });
const { mutateAsync: modifyMapTag } = usePatchModifyMapTagMutation(mapTagId);
const [currentType, setCurrentType] = React.useState<CreateMapTagRequestDtoMapTypeEnum>();
const handleSubmit = async (values: ModifyFormData) => {
try {
const data = await modifyMapTag(values);
if (data?.success) {
closeModal();
message.success('맵 태그가 수정되었습니다.');
}
} catch (e) {
console.error(e);
message.error('맵 태그 수정에 실패했습니다.');
}
};
React.useEffect(() => {
form.setFieldsValue(mapTag?.data);
setCurrentType(mapTag?.data?.mapType || 'Common');
}, [mapTag?.data]);
return (
<Modal
{...modalData}
onOk={form.submit}
okText="확인"
cancelText="닫기"
afterClose={() => {
form.setFieldsValue(mapTag?.data);
setCurrentType(mapTag?.data?.mapType || 'Common');
}}
>
<Form
form={form}
onFinish={handleSubmit}
labelCol={{ span: 24 }}
wrapperCol={{ span: 24 }}
validateMessages={{ required: '필수 입력 항목입니다.' }}
>
<Form.Item name="name" label="이름" rules={[{ required: true }]}>
<Input placeholder="태그 이름을 입력해주세요." />
</Form.Item>
<Form.Item
name="latitude"
label="위도"
rules={[{ required: true }]}
style={{ display: 'none' }}
>
<StyledInputNumber placeholder="위도를 입력해주세요." />
</Form.Item>
<Form.Item
name="longitude"
label="경도"
rules={[{ required: true }]}
style={{ display: 'none' }}
>
<StyledInputNumber placeholder="경도를 입력해주세요." />
</Form.Item>
<Form.Item name="position" label="위치">
<GoogleMapComponent
initialCenter={
mapTag?.data?.latitude && mapTag?.data?.longitude
? {
lat: mapTag.data.latitude,
lng: mapTag.data.longitude
}
: undefined
}
onCenterChange={({ lat, lng }) => {
form.setFieldsValue({
latitude: lat,
longitude: lng
});
}}
/>
</Form.Item>
<Form.Item name="mapType" label="맵 타입" rules={[{ required: true }]}>
<Select
onChange={setCurrentType}
placeholder="맵 타입을 선택해주세요."
options={[
{
label: '일반',
value: 'Common'
},
{
label: '어드벤처',
value: 'Adventure'
},
{
label: '트레저',
value: 'Treasure'
}
]}
/>
</Form.Item>
<Form.Item name="zoomLevel" label="줌 레벨" rules={[{ required: true }]}>
<StyledInputNumber placeholder="줌 레벨을 입력해주세요." />
</Form.Item>
{currentType === 'Common' && (
<Form.Item name="modeId" label="연결할 캠페인 또는 축제">
<Select
placeholder="연결할 캠페인 또는 축제를 선택해주세요."
options={adventures?.data?.map((adventure) => ({
label: adventure.title,
value: adventure.id
}))}
loading={isLoading}
showSearch
filterOption={(input, option) => {
return option?.label?.includes(input) || false;
}}
/>
</Form.Item>
)}
{mapTag?.data?.isActive !== null && mapTag?.data?.isActive !== undefined && (
<Form.Item name="isActive" label="활성화 여부" rules={[{ required: true }]}>
<Switch defaultChecked={mapTag.data.isActive} />
</Form.Item>
)}
</Form>
</Modal>
);
}
const StyledInputNumber = styled(InputNumber)`
width: 100%;
`;
|