Skip to content

Commit 509633d

Browse files
josephmyersGreg Trihus
authored andcommitted
Add confirmation dialog for team deletion (#102)
1 parent 10dbc2b commit 509633d

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/renderer/src/routes/TeamsScreen.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { TeamProvider } from '../context/TeamContext';
2828
import { TeamContext } from '../context/TeamContext';
2929
import { validateEmail } from '../utils/validateEmail';
3030
import { axiosPost } from '../utils/axios';
31+
import Confirm from '../components/AlertDialog';
3132

3233
interface IPersonalSectionProps {
3334
onOpenSettings: () => void;
@@ -373,6 +374,7 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
373374
const { teamUpdate, teamDelete, personalTeam, isDeleting } = ctx.state;
374375
const [open, setOpen] = React.useState(false);
375376
const [teamId, setTeamId] = React.useState<string | undefined>();
377+
const [pendingDelete, setPendingDelete] = React.useState<any>();
376378

377379
const selectedTeam = React.useMemo(() => {
378380
if (!teamId) return undefined;
@@ -396,14 +398,26 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
396398
setTeamId(personalTeam);
397399
setOpen(true);
398400
};
399-
const handleClose = () => setOpen(false);
401+
const handleClose = () => {
402+
setPendingDelete(undefined);
403+
setOpen(false);
404+
};
400405
const handleCommit = (value: ITeamDialog) => {
401406
teamUpdate(value.team as any);
402407
handleClose();
403408
};
404-
const handleDelete = (org: any) => {
405-
teamDelete(org);
406-
handleClose();
409+
const handleDeleteRequest = (org: any) => {
410+
setPendingDelete(org);
411+
};
412+
const handleDeleteConfirmed = async () => {
413+
if (pendingDelete) {
414+
await teamDelete(pendingDelete);
415+
setPendingDelete(undefined);
416+
handleClose();
417+
}
418+
};
419+
const handleDeleteRefused = () => {
420+
setPendingDelete(undefined);
407421
};
408422
const isPersonal = teamId === personalTeam;
409423

@@ -419,7 +433,14 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
419433
onCommit={(v) => handleCommit(v)}
420434
values={{ team: selectedTeam } as any}
421435
disabled={isDeleting}
422-
{...(!isPersonal && { onDelete: (org: any) => handleDelete(org) })}
436+
{...(!isPersonal ? { onDelete: handleDeleteRequest } : {})}
437+
/>
438+
)}
439+
{pendingDelete && (
440+
<Confirm
441+
text={''}
442+
yesResponse={handleDeleteConfirmed}
443+
noResponse={handleDeleteRefused}
423444
/>
424445
)}
425446
{children}

0 commit comments

Comments
 (0)