Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: refetch data after finishing edit #271

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading