"use client";
// components/EditDirectorButton.tsx
// Tiny client island for the director detail page — opens the existing
// EditEntityModal with the director record pre-loaded. The detail page
// is a server component, so it can't host useState itself; this wrapper
// does it. After save, force a hard reload so the page definitely
// shows the just-saved values. router.refresh() alone wasn't always
// picking up server-rendered changes (likely browser back-forward cache
// or React Server Component patching edges); a hard reload is the
// most reliable way to guarantee the user sees fresh data.
import { useState } from "react";
import EditEntityModal from "@/components/EditEntityModal";
import type { YsterbaardDirector } from "@/lib/types";
interface Props {
director: YsterbaardDirector;
}
export default function EditDirectorButton({ director }: Props) {
const [open, setOpen] = useState(false);
const refreshPage = () => {
if (typeof window !== "undefined") {
window.location.reload();
}
};
return (
<>
{
setOpen(false);
// Always hard-reload on close so any cached or stale view is
// replaced with the latest server data.
refreshPage();
}}
onAfterSave={() => {
// After a successful save, hard-reload so the user immediately
// sees the persisted values (and not a stale view that may
// still be in the back-forward cache or React Server Component
// patch state).
refreshPage();
}}
/>
>
);
}