Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/renderer/src/routes/TeamsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { TeamProvider } from '../context/TeamContext';
import { TeamContext } from '../context/TeamContext';
import { validateEmail } from '../utils/validateEmail';
import { axiosPost } from '../utils/axios';
import Confirm from '../components/AlertDialog';

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

const selectedTeam = React.useMemo(() => {
if (!teamId) return undefined;
Expand All @@ -396,14 +398,26 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
setTeamId(personalTeam);
setOpen(true);
};
const handleClose = () => setOpen(false);
const handleClose = () => {
setPendingDelete(undefined);
setOpen(false);
};
const handleCommit = (value: ITeamDialog) => {
teamUpdate(value.team as any);
handleClose();
};
const handleDelete = (org: any) => {
teamDelete(org);
handleClose();
const handleDeleteRequest = (org: any) => {
setPendingDelete(org);
};
const handleDeleteConfirmed = async () => {
if (pendingDelete) {
await teamDelete(pendingDelete);
setPendingDelete(undefined);
handleClose();
}
};
const handleDeleteRefused = () => {
setPendingDelete(undefined);
};
const isPersonal = teamId === personalTeam;

Expand All @@ -419,7 +433,14 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
onCommit={(v) => handleCommit(v)}
values={{ team: selectedTeam } as any}
disabled={isDeleting}
{...(!isPersonal && { onDelete: (org: any) => handleDelete(org) })}
{...(!isPersonal ? { onDelete: handleDeleteRequest } : {})}
/>
)}
{pendingDelete && (
<Confirm
text={''}
yesResponse={handleDeleteConfirmed}
noResponse={handleDeleteRefused}
/>
)}
{children}
Expand Down