-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/handle full team deletion (#553)
- Loading branch information
1 parent
eb28f8c
commit 368e187
Showing
18 changed files
with
305 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Components/Teams/ConfirmFullTeamDeletion/ConfirmFullTeamDeletion.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { FC, useState } from "react"; | ||
import { Button } from "@skbkontur/react-ui"; | ||
import { Flexbox } from "../../Flexbox/FlexBox"; | ||
import { Hovered, HoveredShow } from "../Hovered/Hovered"; | ||
import { Team } from "../../../Domain/Team"; | ||
import { Confirm } from "../Confirm"; | ||
import DeleteIcon from "@skbkontur/react-icons/Delete"; | ||
import { useFyllyDeleteTeam } from "../../../hooks/useFullyDeleteTeam"; | ||
import { fullyDeleteTeamConfirmText } from "../../../helpers/teamOperationsConfirmMessages"; | ||
|
||
interface IConfirmFullTeamDeleteionProps { | ||
team: Team; | ||
} | ||
|
||
export const ConfirmFullTeamDeleteion: FC<IConfirmFullTeamDeleteionProps> = ({ | ||
team, | ||
}: IConfirmFullTeamDeleteionProps) => { | ||
const { id: teamId, name: teamName } = team; | ||
const [isConfirmOpened, setIsConfirmOpened] = useState<boolean>(false); | ||
|
||
const { | ||
handleFullyDeleteTeam, | ||
isFetchingData, | ||
isDeletingContacts, | ||
isDeletingSubscriptions, | ||
isDeletingUsers, | ||
isDeletingTeam, | ||
} = useFyllyDeleteTeam(teamId, !isConfirmOpened); | ||
|
||
const confirmMessage = fullyDeleteTeamConfirmText( | ||
isFetchingData, | ||
isDeletingContacts, | ||
isDeletingSubscriptions, | ||
isDeletingUsers, | ||
isDeletingTeam, | ||
teamName | ||
); | ||
|
||
const isLoading = | ||
isFetchingData || | ||
isDeletingContacts || | ||
isDeletingSubscriptions || | ||
isDeletingUsers || | ||
isDeletingTeam; | ||
|
||
return ( | ||
<Hovered> | ||
<Flexbox align="baseline" direction="row" gap={8}> | ||
<h2>{teamName}</h2> | ||
<HoveredShow> | ||
<Confirm | ||
isLoading={isLoading} | ||
message={confirmMessage} | ||
action={handleFullyDeleteTeam} | ||
errorMessage="An error occurred during full team deletion." | ||
> | ||
<Button | ||
data-tid={`Delete team ${teamName}`} | ||
use={"link"} | ||
icon={<DeleteIcon />} | ||
onClick={() => setIsConfirmOpened(true)} | ||
/> | ||
</Confirm> | ||
</HoveredShow> | ||
</Flexbox> | ||
</Hovered> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export const getExcludeYourselfFromTeamMessage = ( | ||
userName: string, | ||
teamName: string, | ||
currentUserLogin?: string | ||
) => { | ||
if (userName === currentUserLogin) { | ||
return `You are trying to exclude yourself from the "${teamName}". If you do this, you will no longer be able to access this team. Are you sure you want to exclude yourself?`; | ||
} | ||
return `Exclude "${userName}" from "${teamName}"?`; | ||
}; | ||
|
||
export const fullyDeleteTeamConfirmText = ( | ||
isFetchingData: boolean, | ||
isDeletingContacts: boolean, | ||
isDeletingSubscriptions: boolean, | ||
isDeletingUsers: boolean, | ||
isDeletingTeam: boolean, | ||
teamName: string | ||
) => { | ||
switch (true) { | ||
case isFetchingData: | ||
return "Fetching data..."; | ||
case isDeletingContacts: | ||
return "Deleting contacts..."; | ||
case isDeletingSubscriptions: | ||
return "Deleting subscriptions..."; | ||
case isDeletingUsers: | ||
return "Deleting users..."; | ||
case isDeletingTeam: | ||
return "Deleting team..."; | ||
default: | ||
return `Do you really want to remove "${teamName}" team? This action will also delete all team users, contacts and subscriptions.`; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useDeleteUserFromTeamMutation, useGetTeamUsersQuery } from "../services/TeamsApi"; | ||
import { useGetUserQuery } from "../services/UserApi"; | ||
import { useCallback } from "react"; | ||
|
||
export const useDeleteAllUsersFromTeam = (teamId: string, skip?: boolean) => { | ||
const { data: users, isLoading: isGettingUsers } = useGetTeamUsersQuery( | ||
{ | ||
teamId, | ||
handleLoadingLocally: true, | ||
handleErrorLocally: true, | ||
}, | ||
{ skip } | ||
); | ||
const { data: currentUser, isLoading: isGettingCurrentUser } = useGetUserQuery( | ||
{ | ||
handleLoadingLocally: true, | ||
handleErrorLocally: true, | ||
}, | ||
{ skip } | ||
); | ||
const [deleteUserFromTeam, { isLoading: isDeletingUsers }] = useDeleteUserFromTeamMutation(); | ||
|
||
const usersToDelete = users?.filter((user) => user !== currentUser?.login); | ||
|
||
const deleteAllUsersFromTeam = useCallback(async () => { | ||
if (usersToDelete) | ||
for (const user of usersToDelete) { | ||
await deleteUserFromTeam({ | ||
teamId, | ||
userName: user, | ||
handleLoadingLocally: true, | ||
handleErrorLocally: true, | ||
}).unwrap(); | ||
} | ||
}, [usersToDelete]); | ||
|
||
const isGettingTeamUsers = isGettingCurrentUser || isGettingUsers; | ||
|
||
return { isGettingTeamUsers, isDeletingUsers, deleteAllUsersFromTeam }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.