Fix invitation import reactivity and focus imported invitation
This commit is contained in:
@@ -102,6 +102,7 @@ export function InvitationScreen(): React.ReactElement {
|
||||
// Two phases: first the ID input dialog, then the multi-step import flow.
|
||||
const [showIdDialog, setShowIdDialog] = useState(false);
|
||||
const [importingId, setImportingId] = useState<string | null>(null);
|
||||
const [pendingImportedInvitationId, setPendingImportedInvitationId] = useState<string | null>(null);
|
||||
|
||||
// ── Template cache ───────────────────────────────────────────────────────
|
||||
const [templateCache, setTemplateCache] = useState<Map<string, XOTemplate>>(new Map());
|
||||
@@ -161,7 +162,7 @@ export function InvitationScreen(): React.ReactElement {
|
||||
});
|
||||
|
||||
return [importItem, ...invitationItems];
|
||||
}, [invitations, templateCache]);
|
||||
}, [invitations.length, templateCache]);
|
||||
|
||||
const selectedItem = listItems[selectedIndex];
|
||||
const selectedInvitation = selectedItem?.value ?? null;
|
||||
@@ -196,10 +197,30 @@ export function InvitationScreen(): React.ReactElement {
|
||||
/**
|
||||
* Import flow closed (completed or cancelled).
|
||||
*/
|
||||
const handleImportFlowClose = useCallback(() => {
|
||||
const handleImportFlowClose = useCallback((importedInvitationId?: string) => {
|
||||
if (importedInvitationId) {
|
||||
setPendingImportedInvitationId(importedInvitationId);
|
||||
}
|
||||
setImportingId(null);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Once imported invitation is visible in the list, select and focus it.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (!pendingImportedInvitationId) return;
|
||||
|
||||
const importedIndex = listItems.findIndex((item) => {
|
||||
return item.value?.data.invitationIdentifier === pendingImportedInvitationId;
|
||||
});
|
||||
|
||||
if (importedIndex >= 0) {
|
||||
setSelectedIndex(importedIndex);
|
||||
setFocusedPanel('list');
|
||||
setPendingImportedInvitationId(null);
|
||||
}
|
||||
}, [pendingImportedInvitationId, listItems]);
|
||||
|
||||
// ── Action handlers ────────────────────────────────────────────────────
|
||||
|
||||
const acceptInvitation = useCallback(async () => {
|
||||
|
||||
Reference in New Issue
Block a user