diff --git a/client/src/containers/projects/custom-project/header/index.tsx b/client/src/containers/projects/custom-project/header/index.tsx index f3e50b15..67cb9ab8 100644 --- a/client/src/containers/projects/custom-project/header/index.tsx +++ b/client/src/containers/projects/custom-project/header/index.tsx @@ -1,6 +1,6 @@ -import { FC, useCallback } from "react"; +import { FC, useCallback, useState } from "react"; -import { useRouter } from "next/navigation"; +import Link from "next/link"; import { CustomProject as CustomProjectEntity } from "@shared/entities/custom-project.entity"; import { useAtom } from "jotai"; @@ -28,7 +28,7 @@ const CustomProjectHeader: FC = ({ data }) => { useAtom(projectsUIState); const { data: session } = useSession(); const { toast } = useToast(); - const router = useRouter(); + const [saved, setSaved] = useState(false); const SaveProject = useCallback( async (arg: Session | null = session) => { try { @@ -42,7 +42,7 @@ const CustomProjectHeader: FC = ({ data }) => { if (status === 201) { toast({ description: "Project updated successfully." }); - router.push("/my-projects"); + setSaved(true); } if (body?.errors) { @@ -58,13 +58,35 @@ const CustomProjectHeader: FC = ({ data }) => { }); } }, - [session, data, toast, router], + [session, data, toast], ); const handleOnSignIn = useCallback(async () => { // session is undefined when onSignIn callback is called const session = await getSession(); SaveProject(session); }, [SaveProject]); + let ButtonComponent = ( + Save project} + onSignIn={handleOnSignIn} + /> + ); + + if (session) { + ButtonComponent = ( + + ); + } + + if (saved) { + ButtonComponent = ( + + ); + } return ( @@ -85,16 +107,7 @@ const CustomProjectHeader: FC = ({ data }) => { - {session ? ( - - ) : ( - Save project} - onSignIn={handleOnSignIn} - /> - )} + {ButtonComponent} );