diff --git a/frontend/src/views/Teams.svelte b/frontend/src/views/Teams.svelte index bea76ed..25060e7 100644 --- a/frontend/src/views/Teams.svelte +++ b/frontend/src/views/Teams.svelte @@ -18,19 +18,17 @@

Manage Teams

-
-
-
- -
-
+
+ updateActiveTeam(e.target.value)}> + {#each teams as team} + + {/each} + - {#if activeTeam.id !== 'default'} -
+ {#if activeTeam !== 'default'} +
+ on:click={() => deleteTeam(activeTeam)}>Delete {getTeam(activeTeam)?.name}
{/if}
@@ -50,7 +48,7 @@ {role === undefined ? "Unknown Role" : role.name} {/if} - @@ -105,6 +103,7 @@ import UserSelect from "../components/form/UserSelect.svelte"; import RoleSelect from "../components/form/RoleSelect.svelte"; import WrappedSelect from "../components/WrappedSelect.svelte"; + import Dropdown from "../components/form/Dropdown.svelte"; export let currentRoute; let guildId = currentRoute.namedParams.id; @@ -115,20 +114,20 @@ let defaultTeam = {id: 'default', name: 'Default'}; let createName; - let teams = []; + let teams = [defaultTeam]; let roles = []; - let activeTeam = defaultTeam; + let activeTeam = defaultTeam.id; let members = []; let selectedUser; let selectedRole; - function labelMapper(team) { - return team.name; + function getTeam(id) { + return teams.find((team) => team.id === id); } - async function updateActiveTeam() { - const res = await axios.get(`${API_URL}/api/${guildId}/team/${activeTeam.id}`); + async function updateActiveTeam(teamId) { + const res = await axios.get(`${API_URL}/api/${guildId}/team/${teamId}`); if (res.status !== 200) { if (res.status === 429) { notifyRatelimit(); @@ -142,13 +141,13 @@ } async function addUser() { - const res = await axios.put(`${API_URL}/api/${guildId}/team/${activeTeam.id}/${selectedUser.id}?type=0`); + const res = await axios.put(`${API_URL}/api/${guildId}/team/${activeTeam}/${selectedUser.id}?type=0`); if (res.status !== 200) { notifyError(res.data.error); return; } - notifySuccess(`${selectedUser.username} has been added to the support team ${activeTeam.name}`); + notifySuccess(`${selectedUser.username} has been added to the support team ${getTeam(activeTeam).name}`); let entity = { id: selectedUser.id, @@ -160,13 +159,13 @@ } async function addRole() { - const res = await axios.put(`${API_URL}/api/${guildId}/team/${activeTeam.id}/${selectedRole.id}?type=1`); + const res = await axios.put(`${API_URL}/api/${guildId}/team/${activeTeam}/${selectedRole.id}?type=1`); if (res.status !== 200) { notifyError(res.data.error); return; } - notifySuccess(`${selectedRole.name} has been added to the support team ${activeTeam.name}`); + notifySuccess(`${selectedRole.name} has been added to the support team ${getTeam(activeTeam).name}`); let entity = { id: selectedRole.id, @@ -218,8 +217,11 @@ } notifySuccess(`Team deleted successfully`); - activeTeam = defaultTeam; + + activeTeam = defaultTeam.id; teams = teams.filter((team) => team.id !== id); + + await updateActiveTeam(defaultTeam.id); } async function loadTeams() { @@ -250,7 +252,7 @@ loadRoles() ]); - await updateActiveTeam(); // Depends on teams + await updateActiveTeam(defaultTeam.id); // Depends on teams });