Skip to content

Commit

Permalink
hotfix: mockeypatch patch method
Browse files Browse the repository at this point in the history
  • Loading branch information
algoORgoal committed May 14, 2024
1 parent 4b64cd0 commit 47d90e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/features/booth/api/booth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ export const updateBoothOpened = async (
accessToken: string,
boothId: number,
opened: boolean,
latitude: number,
longitude: number,
) => {
const response = await fetch(`${API_URL}/api/booths/${boothId}`, {
method: HTTPMethod.PATCH,
headers: {
[`${HTTPHeaderKey.CONTENT_TYPE}`]: HTTPHeaderValue.APPLICATION_JSON,
[`${HTTPHeaderKey.AUTHORIZATION}`]: getAuthorziationValue(accessToken),
},
body: JSON.stringify({ enabled: opened }),
body: JSON.stringify({ enabled: opened, latitude, longitude }),
});
const data = await response.json();
return data;
Expand Down
13 changes: 12 additions & 1 deletion src/features/booth/ui/SwitchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ import { Label } from "@/src/shared/ui/label";
import { Switch } from "@/src/shared/ui/switch";
import React, { useState } from "react";
import { updateBoothOpened } from "../api/booth";
import { useBoothListStore } from "@/src/shared/model/provider/booth-list-store-provider";

export function SwitchButton({
boothId,
initialOpened,
}: Readonly<{ boothId: number; initialOpened?: boolean }>) {
const [opened, setIsOpened] = useState<boolean>(Boolean(initialOpened));
const booth = useBoothListStore((state) =>
state.booths.filter((booth) => booth.id === boothId),
)[0];
const edit = useBoothListStore((state) => state.edit);

const updateAuthBoothOpened = useAuthFetch(updateBoothOpened);

const toggleBoothOpened = async () => {
await updateAuthBoothOpened(boothId, !opened);
await updateAuthBoothOpened(
boothId,
!opened,
booth.latitude,
booth.longitude,
);
setIsOpened((currentOpened) => !currentOpened);
edit({ ...booth, enabled: !opened });
};

return (
Expand Down
6 changes: 5 additions & 1 deletion src/shared/model/store/booth-draft-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export const createBoothDraftStore =
editDescription: (newDescription) =>
set((state) => ({ ...state, description: newDescription })),
editPosition: (newPosition) =>
set((state) => ({ ...state, position: { ...newPosition } })),
set((state) => ({
...state,
latitude: newPosition.latitude,
longitude: newPosition.longitude,
})),
reset: () =>
set((state) => ({ ...state, ...defaultInitState })),
}),
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/booth/ui/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function Edit({ boothId }: { boothId: number }) {
addMenuItem,
editMenuItem,
removeMemuItem,
enabled,
] = useBoothEditStore((state) => [
state.name,
state.category,
Expand All @@ -81,6 +82,7 @@ export function Edit({ boothId }: { boothId: number }) {
state.addMenuItem,
state.editMenuItem,
state.removeMenuItem,
state.enabled,
]);

const [menuItemParent] = useAutoAnimate();
Expand Down Expand Up @@ -119,7 +121,7 @@ export function Edit({ boothId }: { boothId: number }) {
const router = useRouter();

const onSubmit = async (data: any) => {
await editAuthBooth({ id: boothId, thumbnail, ...data });
await editAuthBooth({ id: boothId, thumbnail, enabled, ...data });
router.push("/");
};

Expand Down

0 comments on commit 47d90e1

Please sign in to comment.