diff --git a/TeamTable.tsx b/TeamTable.tsx new file mode 100644 index 0000000..abd79e9 --- /dev/null +++ b/TeamTable.tsx @@ -0,0 +1,335 @@ +import { + Box, + Button, + Flex, + IconButton, + ListIcon, + ListItem, + Text, + Tooltip, + UnorderedList, + useTheme, + useToast, + Image, +} from '@chakra-ui/react'; +import React, { useEffect, useMemo } from 'react'; +import Present from '../assets/Present.svg'; +import NotPresent from '../assets/notPresent.svg'; + +import { + ConfirmButton, + DataGrid, + Loader, + useToastHook, +} from '@devd-client/devd/components'; +import { useNavigate } from 'react-router-dom'; +import { apiClient } from '@devd-client/api'; +import { createColumnHelper } from '@tanstack/react-table'; +import { QUERY_KEYS, useFetchTeams } from '../apis'; +import { AiOutlineMinusSquare, AiOutlinePlusSquare } from 'react-icons/ai'; +import { useQueryClient } from '@tanstack/react-query'; +import { MdOutlineEdit, MdPersonAddAlt } from 'react-icons/md'; +import { TEAM_DETAILS_QUERY_KEYS } from '@devd-client/devd/team-details'; + +interface TeamViewProps { + team: string; + setTeamLength: any; + appState?: any; + teamLength?: number; + plan?: string; +} + +const TeamView: React.FC = ({ + team, + setTeamLength, + appState, + teamLength, + plan, +}) => { + const queryClient = useQueryClient(); + const { colors } = useTheme(); + const navigate = useNavigate(); + const [loading, setLoading] = React.useState(false); + const [newToast] = useToastHook(); + + const { data: teamsData, isFetching: teamsDataLoading } = useFetchTeams(team); + + const rows: any[] = useMemo(() => teamsData?.dto || [], [teamsData?.dto]); + + useEffect(() => { + setTeamLength(rows.length); + }, [rows, setTeamLength]); + + const columnHelper = createColumnHelper(); + + const columns = useMemo( + () => [ + columnHelper.accessor('name', { + cell: (info) => { + return ( + + {info.row.getCanExpand() ? ( + <> + + + ) : ( + '' + )}{' '} + {info.getValue()} + + ); + }, + header: 'Team Name', + }), + + columnHelper.accessor('description', { + cell: (info) => { + if (!info.getValue()) { + return No Description Added; + } else { + return info.getValue(); + } + }, + header: 'Description', + size: 360, + }), + + columnHelper.accessor('managers', { + cell: (info) => { + let count = 0; + info.row.original.subTeams.forEach((item: any) => { + count += item.managers.length; + }); + return ( + + {info?.getValue()?.length > 0 ? ( + + {info?.getValue()?.map((item: string, idx: number) => ( + + {item} + {info.getValue().length - 1 !== idx && ','} + + ))} + {info.row.original.subTeams.length > 0 ? ( + +{count} in subteams + ) : ( + '' + )} + + ) : ( + + + No Manager Assigned + + {info.row.original.subTeams.length > 0 ? ( + +{count} in subteams + ) : ( + '' + )} + + )} + + ); + }, + header: 'Managers', + }), + columnHelper.accessor('memberCount', { + cell: (info) => { + const rowData = info.row.original as any; + const managersCount = rowData?.managers + ? rowData?.managers.length + : 0; + const membersCount = rowData?.memberCount ? rowData?.memberCount : 0; + const subTeamsCount = rowData?.subTeams ? rowData.subTeams.length : 0; + + + return ( + + {managersCount} Managers + {membersCount} Members + {subTeamsCount} Subteams + + ); + }, + header: 'Members', + size: 50, + meta: { + isNumeric: true, + }, + }), + columnHelper.accessor('setupStates', { + cell: (info) => ( + + + {info.getValue().Communication ? ( + + ) : ( + + )} + Communication + + + {info.getValue().Dora ? ( + + ) : ( + + )} + DORA + + + {info.getValue().Issue ? ( + + ) : ( + + )} + Issue + + + {info.getValue().Git ? ( + + ) : ( + + )} + Git + + + ), + header: 'Config Status', + }), + + columnHelper.accessor('actions', { + cell: (info) => ( + + + } + position={'static'} + onClick={(e) => { + e.preventDefault(); + e.stopPropagation(); + navigate(`/settings/teams/${info.row.original?.name}`); + }} + /> + + + { + if (info.row.original.subTeams.length >= 1) { + newToast({ + message: + 'Cannot delete top level team if sub teams available.', + status: 'error', + }); + } else { + handleDelete(info.row.original?.name); + } + }} + /> + + + } + position={'static'} + onClick={(e) => { + e.preventDefault(); + e.stopPropagation(); + navigate(`/settings/teams/${info.row.original?.name}`, { + state: { tab: 1 }, + }); + }} + /> + + + ), + header: 'Actions', + }), + ], + [teamsData?.dto] + ); + + const handleDelete = (name: string) => { + setLoading(true); + apiClient(`/v1/team/${localStorage.getItem('orgId')}/${name}`, { + method: 'DELETE', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + authorization: `bearer ${localStorage.getItem('token')}`, + }, + }) + .then((res: any) => { + Promise.all([ + queryClient.invalidateQueries([QUERY_KEYS.teams]), + queryClient.invalidateQueries([TEAM_DETAILS_QUERY_KEYS.teamList]), + queryClient.invalidateQueries(['teamMenu']), + ]); + + newToast({ + message: `"${name}" Team has been deleted successfully.`, + status: 'success', + }); + }) + .catch((err: any) => { + newToast({ + message: + err?.message ?? `Some error occurred while deleting ${name}.`, + status: 'error', + }); + }) + .finally(() => { + setLoading(false); + }); + }; + + return ( + <> + + {(loading || teamsDataLoading) && } + + ); +}; + +export default TeamView;