Skip to content

Commit

Permalink
feat: using updateVisibility with petcard
Browse files Browse the repository at this point in the history
  • Loading branch information
Kchanatipz committed Feb 19, 2024
1 parent 68fe230 commit 95faef2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/Card/PetCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

Check failure on line 1 in src/components/Card/PetCard/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `␍⏎`
import dog from "@/assets/dog.webp";
import Button from "@/components/Button";
import PetDetail from "@/components/Card/PetCard/PetDetail";
import TogglePetButton from "@/components/Card/PetCard/TogglePetButton";
import { useUpdateVisibility } from "@/hooks/mutation/useUpdateVisibility";
import { UtcStringToYearMonth } from "@/utils/dateConverter";
import { Icon } from "@iconify/react";
import { useMemo, useState } from "react";
Expand Down Expand Up @@ -47,7 +49,12 @@ const PetCard = ({
isVisibled,
}: PetCardProps) => {
const [visibility, setVisibility] = useState(isVisibled);
const { mutate } = useUpdateVisibility();
const toggleVisibility = () => {
mutate({
id: id,
visibility: !visibility

Check failure on line 56 in src/components/Card/PetCard/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
})

Check failure on line 57 in src/components/Card/PetCard/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
setVisibility((prev) => !prev);
};

Expand Down Expand Up @@ -128,9 +135,9 @@ const PetCard = ({
/>
) : (
<TogglePetButton
visibility={visibility}
onClick={toggleVisibility}
/>
visibility={visibility}

Check failure on line 138 in src/components/Card/PetCard/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
onClick={toggleVisibility}

Check failure on line 139 in src/components/Card/PetCard/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
/>

Check failure on line 140 in src/components/Card/PetCard/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
)}
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/mutation/useUpdateVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { updateVisibility } from "@/api/pets";
import { useMutation } from "@tanstack/react-query";
import toast from 'react-hot-toast'

Check failure on line 3 in src/hooks/mutation/useUpdateVisibility.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'react-hot-toast'` with `"react-hot-toast";`

const useUpdateVisibility = () => {
return useMutation({
mutationFn: ({ id, visibility }: { id: string; visibility: boolean }) =>
updateVisibility(id, visibility),
onSuccess: () => {
toast.success("เปลี่ยนการมองเห็นสำเร็จ")

Check failure on line 10 in src/hooks/mutation/useUpdateVisibility.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
},
onError: () => {
toast.error("มีบางอย่างผิดพลาด")

Check failure on line 13 in src/hooks/mutation/useUpdateVisibility.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
}

Check failure on line 14 in src/hooks/mutation/useUpdateVisibility.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});
};

Expand Down

0 comments on commit 95faef2

Please sign in to comment.