Changed resuce to status to allow cancellation, enabled email notifications
This commit is contained in:
+70
-9
@@ -834,6 +834,7 @@ function App() {
|
||||
const [applyingPhotoCrop, setApplyingPhotoCrop] = useState(false);
|
||||
const [savingBird, setSavingBird] = useState(false);
|
||||
const [savingWorkspace, setSavingWorkspace] = useState(false);
|
||||
const [cancelingRescueRequest, setCancelingRescueRequest] = useState(false);
|
||||
const [savingWorkspaceMember, setSavingWorkspaceMember] = useState(false);
|
||||
const [creatingWorkspace, setCreatingWorkspace] = useState(false);
|
||||
const [creatingIntegrationToken, setCreatingIntegrationToken] = useState(false);
|
||||
@@ -1576,18 +1577,17 @@ function App() {
|
||||
throw new Error('Unable to update rescue verification status.');
|
||||
}
|
||||
|
||||
setAdminRescueWorkspaces((current) =>
|
||||
current.map((entry) => (entry.workspace.id === workspaceId ? { ...entry, workspace: data.workspace! } : entry)),
|
||||
);
|
||||
const nextRescueWorkspaces = adminRescueWorkspaces
|
||||
.map((entry) => (entry.workspace.id === workspaceId ? { ...entry, workspace: data.workspace! } : entry))
|
||||
.filter((entry) => entry.workspace.workspaceType === 'rescue');
|
||||
|
||||
setAdminRescueWorkspaces(nextRescueWorkspaces);
|
||||
setAdminSummary((current) =>
|
||||
current
|
||||
? {
|
||||
...current,
|
||||
pendingRescues: adminRescueWorkspaces.filter((entry) =>
|
||||
entry.workspace.id === workspaceId
|
||||
? rescueVerificationStatus === 'pending'
|
||||
: entry.workspace.rescueVerificationStatus === 'pending',
|
||||
).length,
|
||||
rescueWorkspaces: nextRescueWorkspaces.length,
|
||||
pendingRescues: nextRescueWorkspaces.filter((entry) => entry.workspace.rescueVerificationStatus === 'pending').length,
|
||||
}
|
||||
: current,
|
||||
);
|
||||
@@ -2213,6 +2213,56 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelRescueRequest = async () => {
|
||||
if (!authToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
setError('');
|
||||
setCancelingRescueRequest(true);
|
||||
|
||||
try {
|
||||
const response = await apiFetch('/workspace/rescue-status/cancel', authToken, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(await readErrorMessage(response, 'Unable to cancel rescue status request.'));
|
||||
}
|
||||
|
||||
const data = (await readJsonSafely<{ workspace?: Workspace }>(response)) ?? {};
|
||||
|
||||
if (!data.workspace) {
|
||||
throw new Error('Unable to cancel rescue status request.');
|
||||
}
|
||||
|
||||
const savedWorkspace = data.workspace;
|
||||
|
||||
setWorkspace(savedWorkspace);
|
||||
setAuthSession((current) =>
|
||||
current
|
||||
? {
|
||||
...current,
|
||||
activeWorkspace: savedWorkspace,
|
||||
workspaces: current.workspaces.map((entry) =>
|
||||
entry.workspace.id === savedWorkspace.id ? { ...entry, workspace: savedWorkspace } : entry,
|
||||
),
|
||||
}
|
||||
: current,
|
||||
);
|
||||
setWorkspaceForm({
|
||||
name: savedWorkspace.name,
|
||||
workspaceType: savedWorkspace.workspaceType,
|
||||
billingEmail: savedWorkspace.billingEmail ?? '',
|
||||
billingPlan: isHouseholdPlan(savedWorkspace.billingPlan) ? savedWorkspace.billingPlan : 'household_basic',
|
||||
});
|
||||
} catch (workspaceError) {
|
||||
setError(workspaceError instanceof Error ? workspaceError.message : 'Unable to cancel rescue status request.');
|
||||
} finally {
|
||||
setCancelingRescueRequest(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleWorkspaceMemberSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setError('');
|
||||
@@ -2660,7 +2710,7 @@ function App() {
|
||||
type="button"
|
||||
disabled={updatingRescueWorkspaceId === entry.workspace.id || entry.workspace.rescueVerificationStatus === 'rejected'}
|
||||
>
|
||||
Reject
|
||||
Reject and make household
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
@@ -3195,6 +3245,17 @@ function App() {
|
||||
<article className="summary-card">
|
||||
<strong>{formatRescueVerificationStatus(workspace.rescueVerificationStatus)}</strong>
|
||||
<span>Rescue flocks are read-only until an admin approves their verification.</span>
|
||||
{workspace.rescueVerificationStatus === 'pending' &&
|
||||
(activeMembership?.role === 'owner' || activeMembership?.role === 'assistant') ? (
|
||||
<button
|
||||
className="secondary-button"
|
||||
type="button"
|
||||
onClick={handleCancelRescueRequest}
|
||||
disabled={cancelingRescueRequest}
|
||||
>
|
||||
{cancelingRescueRequest ? 'Canceling request...' : 'Cancel rescue request'}
|
||||
</button>
|
||||
) : null}
|
||||
</article>
|
||||
) : null}
|
||||
<article className="summary-card">
|
||||
|
||||
Reference in New Issue
Block a user