Skip to content

Commit

Permalink
fix: refetch data after finishing edit (#271)
Browse files Browse the repository at this point in the history
Co-authored-by: Pjaijai <paul6a24@hotmail.com>
  • Loading branch information
Pjaijai and pauljaijai committed Dec 4, 2023
1 parent 1f03c8a commit afe3199
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions client/modules/profile/edit/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import React, { useEffect, useMemo, useState } from "react"
import { StaticImport } from "next/dist/shared/lib/get-img-props"
import { useRouter } from "next/navigation"
import { conditionalValidation } from "@/modules/profile/form/validation.ts/conditional"
import { maximumWordValidation } from "@/modules/profile/form/validation.ts/max-word"
import { nameValidation } from "@/modules/profile/form/validation.ts/name"
Expand Down Expand Up @@ -48,6 +47,7 @@ interface IEdiProfileTemplate {
isReferer: boolean
isReferee: boolean
setIsEditMode: (value: boolean) => void
refetchProfile: () => void
}

const EditProfileTemplate: React.FunctionComponent<IEdiProfileTemplate> = ({
Expand All @@ -66,6 +66,7 @@ const EditProfileTemplate: React.FunctionComponent<IEdiProfileTemplate> = ({
isReferee,
isProfileLoading,
setIsEditMode,
refetchProfile,
}) => {
const formSchema = z
.object({
Expand Down Expand Up @@ -144,7 +145,6 @@ const EditProfileTemplate: React.FunctionComponent<IEdiProfileTemplate> = ({
}
)

const router = useRouter()
const { toast } = useToast()
const [image, setImage] = useState<any | null>(null)
const [base64Image, setBase64Image] = useState<string | StaticImport | null>(
Expand Down Expand Up @@ -280,7 +280,8 @@ const EditProfileTemplate: React.FunctionComponent<IEdiProfileTemplate> = ({
toast({
title: "個人檔案更改成功!",
})
router.push("/")
setIsEditMode(false)
refetchProfile()
},
onSettled: () => {
setIsSubmitting(false)
Expand Down
3 changes: 2 additions & 1 deletion client/modules/profile/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CommonPageLayout from "@/components/layouts/common"

const ProfileTemplate = ({ userUuid }: { userUuid: string }) => {
const [isEditMode, setIsEditMode] = useState(false)
const { data: profile, isLoading } = useGetUserprofile(userUuid)
const { data: profile, isLoading, refetch } = useGetUserprofile(userUuid)

if (!userUuid || (!isLoading && !profile))
return (
Expand Down Expand Up @@ -76,6 +76,7 @@ const ProfileTemplate = ({ userUuid }: { userUuid: string }) => {
isReferer={profile.is_referer}
isProfileLoading={isLoading}
setIsEditMode={setIsEditMode}
refetchProfile={refetch}
/>
)}
</CommonPageLayout>
Expand Down

0 comments on commit afe3199

Please sign in to comment.