-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor communityForm and reuse for add/edit community page
- Loading branch information
1 parent
1916a9b
commit 2d71dec
Showing
4 changed files
with
472 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
"use client"; | ||
|
||
import { | ||
useSuspenseQuery, | ||
} from "@tanstack/react-query"; | ||
import { useSuspenseQuery } from "@tanstack/react-query"; | ||
import { listCommunitiesQuery } from "@/lib/api"; | ||
import { useFormState, useFormStatus } from "react-dom"; | ||
import { updateCommunity } from "@/app/actions"; | ||
import CommunityForm from "@/components/organisms/forms/community-form"; | ||
|
||
const defaultState: ReturnType<typeof updateCommunity> = Promise.resolve({ | ||
ok: false, | ||
}); | ||
|
||
export default function CommunityDetailsPage({ | ||
params, | ||
}: { | ||
params: { id: string }; | ||
}) { | ||
console.log("details page", params.id); | ||
const { data, isLoading } = useSuspenseQuery(listCommunitiesQuery); | ||
const community = data?.data?.find((com) => com.id === parseInt(params.id)); | ||
|
||
console.log('details', { community, id: params.id }) | ||
const [state, formAction] = useFormState<ReturnType<typeof updateCommunity>>( | ||
updateCommunity, | ||
defaultState | ||
); | ||
|
||
const { pending } = useFormStatus(); | ||
|
||
console.log("details", { community, id: params.id }); | ||
if (isLoading || !community) { | ||
return <div>Loading...</div>; | ||
} | ||
return ( | ||
<p>Edit: {community?.name}</p> | ||
<CommunityForm | ||
formAction={(formdata) => { | ||
formdata.append("communityId", community.id.toString()); | ||
formAction(formdata); | ||
}} | ||
state={state} | ||
defaultValues={community} | ||
pending={pending} | ||
/> | ||
); | ||
} |
Oops, something went wrong.