* Prevents users from deleting the same schedule multiple times due to delay before the schedule disappears. It also applies the same fix to team disband. Schedule deletion:  Team disband:  Fixes issue [#2569](https://github.com/calcom/cal.com/issues/2569) Bug fix (non-breaking change which fixes an issue) **apps/web/components/LightLoader.tsx** → this file was created in order to make a light color loading spinner available. It's necessary when we need to display a loading spinner above dark backgrounds. **apps/web/components/availability/ScheduleListItem.tsx** → this component was created in order to give a schedule list item its own state. * Removing a "setTimeout" that was only used for testing purposes * Adding a code review suggestion to my modifications * Changing loading style * Cleanup * Avoids using unnecessary state * Revert "Adding a code review suggestion to my modifications" This reverts commit b5e40062d71157ca1d9384fb1f5c30d50625809d. * Reverts some changes * Renames isLoading Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Omar López <zomars@me.com>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import showToast from "@calcom/lib/notification";
|
|
|
|
import { inferQueryOutput, trpc } from "@lib/trpc";
|
|
|
|
import TeamListItem from "./TeamListItem";
|
|
|
|
interface Props {
|
|
teams: inferQueryOutput<"viewer.teams.list">;
|
|
}
|
|
|
|
export default function TeamList(props: Props) {
|
|
const utils = trpc.useContext();
|
|
|
|
function selectAction(action: string, teamId: number) {
|
|
switch (action) {
|
|
case "disband":
|
|
deleteTeam(teamId);
|
|
break;
|
|
}
|
|
}
|
|
|
|
const deleteTeamMutation = trpc.useMutation("viewer.teams.delete", {
|
|
async onSuccess() {
|
|
await utils.invalidateQueries(["viewer.teams.list"]);
|
|
},
|
|
async onError(err) {
|
|
showToast(err.message, "error");
|
|
},
|
|
});
|
|
|
|
function deleteTeam(teamId: number) {
|
|
deleteTeamMutation.mutate({ teamId });
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<ul className="mb-2 divide-y divide-neutral-200 rounded border bg-white">
|
|
{props.teams.map((team) => (
|
|
<TeamListItem
|
|
key={team?.id as number}
|
|
team={team}
|
|
onActionSelect={(action: string) => selectAction(action, team?.id as number)}
|
|
isLoading={deleteTeamMutation.isLoading}
|
|
/>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|