fix: team switching
This commit is contained in:
parent
4c5e71f33c
commit
570b286ef9
@ -160,6 +160,7 @@ export async function getTeam(request: FastifyRequest<OnlyId>, reply: FastifyRep
|
||||
const invitations = await prisma.teamInvitation.findMany({ where: { teamId: team.id } });
|
||||
const { teams } = await prisma.user.findUnique({ where: { id: userId }, include: { teams: true } })
|
||||
return {
|
||||
currentTeam: teamId,
|
||||
team,
|
||||
teams,
|
||||
permissions,
|
||||
|
@ -25,6 +25,8 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let team: any;
|
||||
export let currentTeam: string;
|
||||
export let teams: any;
|
||||
import { page } from '$app/stores';
|
||||
import { errorNotification, handlerNotFoundLoad } from '$lib/common';
|
||||
@ -40,18 +42,21 @@
|
||||
if (sure) {
|
||||
try {
|
||||
await del(`/iam/team/${id}`, { id });
|
||||
const switchTeam = teams.find((team: any) => team.id !== id)
|
||||
const payload = await get(`/user?teamId=${switchTeam.id}`);
|
||||
if (payload.token) {
|
||||
Cookies.set('token', payload.token, {
|
||||
path: '/'
|
||||
});
|
||||
$appSession.teamId = payload.teamId;
|
||||
$appSession.userId = payload.userId;
|
||||
$appSession.permission = payload.permission;
|
||||
$appSession.isAdmin = payload.isAdmin;
|
||||
return window.location.assign('/iam');
|
||||
if (currentTeam === id) {
|
||||
const switchTeam = teams.find((team: any) => team.id !== id);
|
||||
const payload = await get(`/user?teamId=${switchTeam.id}`);
|
||||
if (payload.token) {
|
||||
Cookies.set('token', payload.token, {
|
||||
path: '/'
|
||||
});
|
||||
$appSession.teamId = payload.teamId;
|
||||
$appSession.userId = payload.userId;
|
||||
$appSession.permission = payload.permission;
|
||||
$appSession.isAdmin = payload.isAdmin;
|
||||
return window.location.assign('/iam');
|
||||
}
|
||||
}
|
||||
|
||||
return await goto('/iam', { replaceState: true });
|
||||
} catch (error) {
|
||||
return errorNotification(error);
|
||||
@ -62,16 +67,18 @@
|
||||
|
||||
{#if id !== 'new'}
|
||||
<nav class="nav-side">
|
||||
<button
|
||||
on:click={deleteTeam}
|
||||
type="submit"
|
||||
disabled={!$appSession.isAdmin}
|
||||
class:hover:text-red-500={$appSession.isAdmin}
|
||||
class="icons tooltip tooltip-primary tooltip-left bg-transparent text-sm"
|
||||
data-tip={$appSession.isAdmin
|
||||
? 'Delete'
|
||||
: $t('destination.permission_denied_delete_destination')}><DeleteIcon /></button
|
||||
>
|
||||
{#if team.id !== '0'}
|
||||
<button
|
||||
on:click={deleteTeam}
|
||||
type="submit"
|
||||
disabled={!$appSession.isAdmin}
|
||||
class:hover:text-red-500={$appSession.isAdmin}
|
||||
class="icons tooltip tooltip-primary tooltip-left bg-transparent text-sm"
|
||||
data-tip={$appSession.isAdmin
|
||||
? 'Delete'
|
||||
: $t('destination.permission_denied_delete_destination')}><DeleteIcon /></button
|
||||
>
|
||||
{/if}
|
||||
</nav>
|
||||
{/if}
|
||||
<slot />
|
||||
|
Loading…
x
Reference in New Issue
Block a user