Skip to content

Commit

Permalink
HOTFIX: 새로운 맛집 추가 body 형식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
oooppq committed Sep 3, 2023
1 parent b7b3d37 commit e56f3e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
45 changes: 28 additions & 17 deletions src/pages/Judge/JudgeNew/JudgeNewDoneModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,34 @@ const JudgeNewDoneModal = ({ setIsDone }) => {
const judgeNewStates = useSelector((state) => state.judgeNew);
const accessToken = useSelector((state) => state.userAuth.accessToken);
const fd = new FormData();
Object.entries(judgeNewStates).forEach(([key, value]) => {
if (value) {
// fd.append('locationCategoryName', value.name);
// else if (key === 'locationTag') fd.append('locationTagName', value.name);
if (key === 'locationCategory') return;
if (key === 'foodCategory') fd.append('foodCategoryName', value.name);
// else if (key === 'restaurantImage') fd.append(reader.result.toString());
else if (key === 'recommendCategory') {
if (value.length) {
fd.append(
'recommendCategoryIds',
value.map((cat) => cat.id)
);
} else fd.append('recommendCategoryIds', null);
} else fd.append(key, value);
} else fd.append(key, null);
});
const createDto = {
restaurantName: judgeNewStates.restaurantName,
address: judgeNewStates.address,
recommendCategoryIds: judgeNewStates.recommendCategory.map((cat) => cat.id),
longitude: judgeNewStates.longitude,
latitude: judgeNewStates.latitude,
introduction: judgeNewStates.introduction,
foodCategoryName: judgeNewStates.foodCategory.name,
};
fd.append('restaurantImage', judgeNewStates.restaurantImage);
fd.append('createDto', JSON.stringify(createDto));
// Object.entries(judgeNewStates).forEach(([key, value]) => {
// if (value) {
// // fd.append('locationCategoryName', value.name);
// // else if (key === 'locationTag') fd.append('locationTagName', value.name);
// if (key === 'locationCategory') return;
// if (key === 'foodCategory') fd.append('foodCategoryName', value.name);
// // else if (key === 'restaurantImage') fd.append(reader.result.toString());
// else if (key === 'recommendCategory') {
// if (value.length) {
// fd.append(
// 'recommendCategoryIds',
// value.map((cat) => cat.id)
// );
// } else fd.append('recommendCategoryIds', null);
// } else fd.append(key, value);
// } else fd.append(key, null);
// });

const { mutate, isLoading } = useMutation((toSend) =>
axios.post(
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Judge/JudgeNew/JudgeNewGetPhoto.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ const JudgeNewGetPhoto = () => {
accept="image/*"
onChange={(e) => {
if (e.target.files && e.target.files.length) {
dispatch(setRestaurantImage(e.target.files[0]));

const reader = new FileReader();
reader.readAsDataURL(e.target.files[0]);
reader.onloadend = () => {
if (reader.result) {
dispatch(setRestaurantImage(reader.result.toString()));
// dispatch(setRestaurantImage(reader.result.toString()));
setImg(reader.result.toString());
}
};
Expand Down

0 comments on commit e56f3e7

Please sign in to comment.