fix: reset editor state on section change to ensure proper template editing
This commit is contained in:
parent
40a01ef665
commit
fb623b26a2
@ -21,6 +21,7 @@ export default function ContractManagementPage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [section, setSection] = useState('templates');
|
const [section, setSection] = useState('templates');
|
||||||
const [editingTemplateId, setEditingTemplateId] = useState<string | null>(null);
|
const [editingTemplateId, setEditingTemplateId] = useState<string | null>(null);
|
||||||
|
const [editorKey, setEditorKey] = useState(0);
|
||||||
|
|
||||||
useEffect(() => { setMounted(true); }, []);
|
useEffect(() => { setMounted(true); }, []);
|
||||||
|
|
||||||
@ -56,7 +57,17 @@ export default function ContractManagementPage() {
|
|||||||
{NAV.map((item) => (
|
{NAV.map((item) => (
|
||||||
<button
|
<button
|
||||||
key={item.key}
|
key={item.key}
|
||||||
onClick={() => setSection(item.key)}
|
onClick={() => {
|
||||||
|
if (section === 'editor' && item.key !== 'editor') {
|
||||||
|
setEditingTemplateId(null);
|
||||||
|
setEditorKey((k) => k + 1);
|
||||||
|
}
|
||||||
|
if (item.key === 'editor') {
|
||||||
|
setEditingTemplateId(null);
|
||||||
|
setEditorKey((k) => k + 1);
|
||||||
|
}
|
||||||
|
setSection(item.key);
|
||||||
|
}}
|
||||||
className={`flex flex-shrink-0 items-center gap-2 px-4 py-2 rounded-lg font-medium transition whitespace-nowrap text-sm md:text-base
|
className={`flex flex-shrink-0 items-center gap-2 px-4 py-2 rounded-lg font-medium transition whitespace-nowrap text-sm md:text-base
|
||||||
${section === item.key
|
${section === item.key
|
||||||
? 'bg-blue-900 text-blue-50 shadow'
|
? 'bg-blue-900 text-blue-50 shadow'
|
||||||
@ -99,6 +110,7 @@ export default function ContractManagementPage() {
|
|||||||
refreshKey={refreshKey}
|
refreshKey={refreshKey}
|
||||||
onEdit={(id) => {
|
onEdit={(id) => {
|
||||||
setEditingTemplateId(id);
|
setEditingTemplateId(id);
|
||||||
|
setEditorKey((k) => k + 1);
|
||||||
setSection('editor');
|
setSection('editor');
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -111,15 +123,18 @@ export default function ContractManagementPage() {
|
|||||||
Create Template
|
Create Template
|
||||||
</h2>
|
</h2>
|
||||||
<ContractEditor
|
<ContractEditor
|
||||||
|
key={`${editorKey}-${editingTemplateId ?? 'new'}`}
|
||||||
editingTemplateId={editingTemplateId}
|
editingTemplateId={editingTemplateId}
|
||||||
onCancelEdit={() => {
|
onCancelEdit={() => {
|
||||||
setEditingTemplateId(null);
|
setEditingTemplateId(null);
|
||||||
|
setEditorKey((k) => k + 1);
|
||||||
setSection('templates');
|
setSection('templates');
|
||||||
}}
|
}}
|
||||||
onSaved={(info) => {
|
onSaved={(info) => {
|
||||||
bumpRefresh();
|
bumpRefresh();
|
||||||
if (info?.action === 'revised') {
|
if (info?.action === 'revised') {
|
||||||
setEditingTemplateId(null);
|
setEditingTemplateId(null);
|
||||||
|
setEditorKey((k) => k + 1);
|
||||||
setSection('templates');
|
setSection('templates');
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user