-
Notifications
You must be signed in to change notification settings - Fork 670
Expand file tree
/
Copy path+page.svelte
More file actions
90 lines (83 loc) · 2.78 KB
/
+page.svelte
File metadata and controls
90 lines (83 loc) · 2.78 KB
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
<script lang="ts">
import { page } from '$app/state';
import { m } from '$paraglide/messages';
import { toCamelCase } from '$lib/utils/locales';
import { safeTranslate } from '$lib/utils/i18n';
import { getLocale } from '$paraglide/runtime';
import Anchor from '$lib/components/Anchor/Anchor.svelte';
import { canPerformAction } from '$lib/utils/access-control';
import type { PageData } from './$types';
function filterUserData() {
const filtered = {};
const filter = ['id', 'is_active'];
const sortedKeys = ['last_name', 'first_name', 'email', 'date_joined'];
sortedKeys.forEach((key) => {
if (!filter.includes(key) && Object.prototype.hasOwnProperty.call(page.data.user, key)) {
const str = toCamelCase(key);
if (key === 'date_joined')
filtered[str] = new Date(page.data.user[key]).toLocaleString(getLocale());
else filtered[str] = page.data.user[key];
}
});
return filtered;
}
const user = page.data.user;
const canEditObject: boolean = canPerformAction({
user,
action: 'change',
model: 'user',
domain: user.root_folder_id
});
interface Props {
data: PageData;
}
let { data }: Props = $props();
</script>
<div class="flex flex-col bg-white card shadow-lg p-4 space-y-4">
<div class="flex flex-row items-center justify-between">
<h1 class="text-xl font-semibold">
{data.currentUser.first_name}
{data.currentUser.last_name}
</h1>
<div>
{#if user.is_local}
<Anchor href="my-profile/change-password" class="btn preset-filled-primary-500 h-fit"
><i class="fa-solid fa-key mr-2"></i>{m.changePassword()}</Anchor
>
{/if}
{#if canEditObject}
<Anchor
href="/users/{data.currentUser.id}/edit?next=/my-profile"
class="btn preset-filled-primary-500 h-fit"
><i class="fa-solid fa-pen-to-square mr-2"></i>{m.edit()}</Anchor
>
{/if}
<Anchor href="my-profile/settings" class="btn preset-filled-primary-500 h-fit"
><i class="fa-solid fa-sliders mr-2"></i>{m.settings()}</Anchor
>
</div>
</div>
<div class="flex flex-row w-full space-x-2">
<div class="flex flex-col w-1/2 card bg-white p-2 space-y-4">
{#each Object.entries(filterUserData()) as [label, value]}
<div class="flex flex-col">
<p class="font-semibold text-sm">{safeTranslate(label)}</p>
<p class="text-sm">{value}</p>
</div>
{/each}
</div>
<div class="flex flex-col w-1/2 card bg-white p-2 space-y-4">
<h2 class="text-xl mb-1 font-semibold">{m.myUserGroups()}</h2>
<div class="overflow-auto space-y-2">
{#each data.currentUser.user_groups as group}
<div class="flex flex-row items-center">
{#if group.builtin}
<span class="badge preset-tonal-primary mr-2">{m.builtin()}</span>
{/if}
<p class="font-semibold text-sm">{group.str}</p>
</div>
{/each}
</div>
</div>
</div>
</div>