-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdata-table-actions.svelte
139 lines (135 loc) · 3.62 KB
/
data-table-actions.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<script lang="ts">
import * as Tooltip from '$lib/components/ui/tooltip/index.js';
import Button, { buttonVariants } from '$lib/components/ui/button/button.svelte';
import { StateInside, type State } from '$lib/types/state';
import { Guest, type PersonType } from '$lib/types/person';
import { ArrowLeftRight, Handshake, LogIn, LogOut } from 'lucide-svelte';
import { tick } from 'svelte';
import { cn } from '$lib/utils';
import { toggleStateFormStore } from '$lib/stores/toggleState.svelte';
import { showGuestsFormStore } from '$lib/stores/showGuests.svelte';
let {
personId,
guarantorFname,
guarantorLname,
guarantorIdentifier,
personType,
personState,
building,
userBuilding,
toggleStateFormSubmit,
toggleGuestStateFormSubmit,
showGuestsFormSubmit
}: {
personId: number;
guarantorFname: string | null;
guarantorLname: string | null;
guarantorIdentifier: string | null;
personType: PersonType;
personState: State;
building: string | null;
userBuilding: string;
toggleStateFormSubmit: (submitter?: HTMLElement | Event | EventTarget | null) => void;
toggleGuestStateFormSubmit: (submitter?: HTMLElement | Event | EventTarget | null) => void;
showGuestsFormSubmit: (submitter?: HTMLElement | Event | EventTarget | null) => void;
} = $props();
const inside = $derived(personState === StateInside);
const sameBuilding = $derived(userBuilding === building);
</script>
<div class="flex">
{#if inside && sameBuilding}
{#if guarantorFname && guarantorLname && guarantorIdentifier}
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger
onclick={() => {
toggleStateFormStore.personId = personId;
tick().then(() => {
if (personType === Guest) {
toggleGuestStateFormSubmit();
} else {
toggleStateFormSubmit();
}
});
}}
class={cn('w-full', buttonVariants({ variant: 'outline' }))}
>
<LogOut />
<span class="hidden sm:block">Release</span>
</Tooltip.Trigger>
<Tooltip.Content>
<span>{guarantorFname} {guarantorLname} ({guarantorIdentifier})</span>
</Tooltip.Content>
</Tooltip.Root>
</Tooltip.Provider>
{:else}
<Button
onclick={() => {
toggleStateFormStore.personId = personId;
tick().then(() => {
if (personType === Guest) {
toggleGuestStateFormSubmit();
} else {
toggleStateFormSubmit();
}
});
}}
variant="outline"
class="w-full"
>
<LogOut />
<span class="hidden sm:block">Release</span>
</Button>
{/if}
{:else if personType !== Guest}
<Button
onclick={() => {
toggleStateFormStore.personId = personId;
tick().then(() => toggleStateFormSubmit());
}}
variant="outline"
class="w-full"
>
{#if inside}
<ArrowLeftRight />
<span class="hidden sm:block">Transfer</span>
{:else}
<LogIn />
<span class="hidden sm:block">Admit</span>
{/if}
</Button>
{:else}
<Button
onclick={() => {
toggleStateFormStore.dialogOpen = true;
toggleStateFormStore.personId = personId;
}}
type="button"
variant="outline"
class="w-full"
>
{#if inside}
<ArrowLeftRight />
<span class="hidden sm:block">Transfer</span>
{:else}
<LogIn />
<span class="hidden sm:block">Admit</span>
{/if}
</Button>
{/if}
{#if personType !== Guest}
<Button
onclick={() => {
showGuestsFormStore.dialogOpen = true;
showGuestsFormStore.guarantorId = personId;
tick().then(() => showGuestsFormSubmit());
}}
type="button"
variant="outline"
class="w-full"
>
<Handshake />
<span class="hidden sm:block">Show guests</span>
</Button>
{/if}
</div>