Skip to content

Commit c21df79

Browse files
committed
fix(dashboard): fix crash on general tab for gatekeeper-only users
useFormContext and useDashboardEventEditionContext were called at the top of DashboardEventGeneral, but the FormProvider is only mounted for organizers. React evaluates JSX expressions (including form.handleSubmit) before RoleBasedViewMode can decide to render the fallback, so the null form reference crashed even though the form UI was never shown. Extract the organizer-only content into a sub-component so the form hooks are only called when the component actually mounts (organizer path).
1 parent b1a6efb commit c21df79

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

app/(dashboard)/dashboard/event/[id]/(default)/dashboard-event-general.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ import RoleBasedViewMode from "@/components/widgets/permissions/view-mode";
1212
import { EventFormSchemaType } from "@/types/schemas";
1313
import { useDashboardEventEditionContext } from "@/components/providers/dashboard-event-edition-context-provider";
1414

15-
export default function DashboardEventGeneral() {
15+
// Extracted so that useFormContext and useDashboardEventEditionContext are
16+
// only called when the FormProvider is actually mounted (organizer path).
17+
function DashboardEventGeneralOrganizerForm() {
1618
const t = useTranslations("dashboard.eventDetails.header");
17-
const { eventInfo, roles } = useDashboardEventContext();
1819
const form = useFormContext<EventFormSchemaType>();
1920
const { isSubmittable, isUpdating, save } = useDashboardEventEditionContext();
2021

2122
return (
22-
<RoleBasedViewMode
23-
roles={roles}
24-
allowedRoles={["organizer"]}
25-
fallback={<MarkdownPreview markdownString={eventInfo.description} />}
26-
>
23+
<>
2724
<DashboardEventInfo />
2825
<div className="my-10" />
2926

@@ -41,6 +38,20 @@ export default function DashboardEventGeneral() {
4138
{t("saveChanges")}
4239
</Button>
4340
</form>
41+
</>
42+
);
43+
}
44+
45+
export default function DashboardEventGeneral() {
46+
const { eventInfo, roles } = useDashboardEventContext();
47+
48+
return (
49+
<RoleBasedViewMode
50+
roles={roles}
51+
allowedRoles={["organizer"]}
52+
fallback={<MarkdownPreview markdownString={eventInfo.description} />}
53+
>
54+
<DashboardEventGeneralOrganizerForm />
4455
</RoleBasedViewMode>
4556
);
4657
}

0 commit comments

Comments
 (0)