Account.svelte 16.9 KB
Newer Older
1
<script lang="ts">
Jannik Streidl's avatar
Jannik Streidl committed
2
	import { toast } from 'svelte-sonner';
3
	import { onMount, getContext } from 'svelte';
4
5

	import { user } from '$lib/stores';
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
6
	import { updateUserProfile, createAPIKey, getAPIKey } from '$lib/apis/auths';
7
8

	import UpdatePassword from './Account/UpdatePassword.svelte';
9
	import { getGravatarUrl } from '$lib/apis/utils';
10
	import { generateInitialsImage, canvasPixelTest } from '$lib/utils';
Timothy J. Baek's avatar
Timothy J. Baek committed
11
	import { copyToClipboard } from '$lib/utils';
Timothy J. Baek's avatar
Timothy J. Baek committed
12
13
	import Plus from '$lib/components/icons/Plus.svelte';
	import Tooltip from '$lib/components/common/Tooltip.svelte';
14

15
16
	const i18n = getContext('i18n');

17
18
19
20
	export let saveHandler: Function;

	let profileImageUrl = '';
	let name = '';
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
21

Timothy J. Baek's avatar
Timothy J. Baek committed
22
23
	let showJWTToken = false;
	let JWTTokenCopied = false;
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
24
25
26
27
28

	let APIKey = '';
	let showAPIKey = false;
	let APIKeyCopied = false;

29
	let profileImageInputElement: HTMLInputElement;
30
31

	const submitHandler = async () => {
Timothy J. Baek's avatar
Timothy J. Baek committed
32
33
34
35
		if (name !== $user.name) {
			if (profileImageUrl === generateInitialsImage($user.name) || profileImageUrl === '') {
				profileImageUrl = generateInitialsImage(name);
			}
Danny Liu's avatar
Danny Liu committed
36
		}
37

38
39
40
41
42
43
44
45
46
47
48
49
50
		const updatedUser = await updateUserProfile(localStorage.token, name, profileImageUrl).catch(
			(error) => {
				toast.error(error);
			}
		);

		if (updatedUser) {
			await user.set(updatedUser);
			return true;
		}
		return false;
	};

Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
51
52
53
	const createAPIKeyHandler = async () => {
		APIKey = await createAPIKey(localStorage.token);
		if (APIKey) {
liu.vaayne's avatar
liu.vaayne committed
54
55
56
57
58
59
			toast.success($i18n.t('API Key created.'));
		} else {
			toast.error($i18n.t('Failed to create API Key.'));
		}
	};

Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
60
	onMount(async () => {
61
62
		name = $user.name;
		profileImageUrl = $user.profile_image_url;
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
63
64
65
66
67

		APIKey = await getAPIKey(localStorage.token).catch((error) => {
			console.log(error);
			return '';
		});
68
69
70
71
	});
</script>

<div class="flex flex-col h-full justify-between text-sm">
Timothy J. Baek's avatar
Timothy J. Baek committed
72
	<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-[22rem]">
73
74
		<input
			id="profile-image-input"
75
			bind:this={profileImageInputElement}
76
77
78
79
			type="file"
			hidden
			accept="image/*"
			on:change={(e) => {
80
				const files = profileImageInputElement.files ?? [];
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
				let reader = new FileReader();
				reader.onload = (event) => {
					let originalImageUrl = `${event.target.result}`;

					const img = new Image();
					img.src = originalImageUrl;

					img.onload = function () {
						const canvas = document.createElement('canvas');
						const ctx = canvas.getContext('2d');

						// Calculate the aspect ratio of the image
						const aspectRatio = img.width / img.height;

						// Calculate the new width and height to fit within 100x100
						let newWidth, newHeight;
						if (aspectRatio > 1) {
							newWidth = 100 * aspectRatio;
							newHeight = 100;
						} else {
							newWidth = 100;
							newHeight = 100 / aspectRatio;
						}

						// Set the canvas size
						canvas.width = 100;
						canvas.height = 100;

						// Calculate the position to center the image
						const offsetX = (100 - newWidth) / 2;
						const offsetY = (100 - newHeight) / 2;

						// Draw the image on the canvas
						ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight);

						// Get the base64 representation of the compressed image
						const compressedSrc = canvas.toDataURL('image/jpeg');

						// Display the compressed image
						profileImageUrl = compressedSrc;

122
						profileImageInputElement.files = null;
123
124
125
126
127
128
129
130
131
132
133
134
					};
				};

				if (
					files.length > 0 &&
					['image/gif', 'image/jpeg', 'image/png'].includes(files[0]['type'])
				) {
					reader.readAsDataURL(files[0]);
				}
			}}
		/>

Timothy J. Baek's avatar
Timothy J. Baek committed
135
		<!-- <div class="flex space-x-5">
136
137
			<div class="flex flex-col">
				<div class="self-center">
Timothy J. Baek's avatar
Timothy J. Baek committed
138
139
					<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Profile')}</div>

140
141
142
					<button
						class="relative rounded-full dark:bg-gray-700"
						type="button"
Timothy J. Baek's avatar
Timothy J. Baek committed
143
144
145
						on:click={() => {
							profileImageInputElement.click();
						}}
146
					>
147
						<img
148
							src={profileImageUrl !== '' ? profileImageUrl : generateInitialsImage(name)}
149
							alt="profile"
Timothy J. Baek's avatar
Timothy J. Baek committed
150
							class=" rounded-full size-20 object-cover"
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
						/>

						<div
							class="absolute flex justify-center rounded-full bottom-0 left-0 right-0 top-0 h-full w-full overflow-hidden bg-gray-700 bg-fixed opacity-0 transition duration-300 ease-in-out hover:opacity-50"
						>
							<div class="my-auto text-gray-100">
								<svg
									xmlns="http://www.w3.org/2000/svg"
									viewBox="0 0 20 20"
									fill="currentColor"
									class="w-5 h-5"
								>
									<path
										d="m2.695 14.762-1.262 3.155a.5.5 0 0 0 .65.65l3.155-1.262a4 4 0 0 0 1.343-.886L17.5 5.501a2.121 2.121 0 0 0-3-3L3.58 13.419a4 4 0 0 0-.885 1.343Z"
									/>
								</svg>
							</div>
168
						</div>
169
170
					</button>
				</div>
171
172
			</div>

Timothy J. Baek's avatar
Timothy J. Baek committed
173
			<div class="flex-1 flex flex-col self-center">
174
				<div class="flex flex-col w-full">
175
					<div class=" mb-1 text-xs text-gray-500">{$i18n.t('Name')}</div>
176
177
178

					<div class="flex-1">
						<input
Timothy J. Baek's avatar
Timothy J. Baek committed
179
							class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
180
181
182
183
184
							type="text"
							bind:value={name}
							required
						/>
					</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

					<div class="mt-2">
						<button
							class=" text-xs text-center text-gray-800 dark:text-gray-400 rounded-full px-4 py-0.5 bg-gray-100 dark:bg-gray-850"
							on:click={async () => {
								const url = await getGravatarUrl($user.email);

								profileImageUrl = url;
							}}>{$i18n.t('Use Gravatar')}</button
						>

						<button
							class=" text-xs text-center text-gray-800 dark:text-gray-400 rounded-full px-4 py-0.5 bg-gray-100 dark:bg-gray-850"
							on:click={async () => {
								if (canvasPixelTest()) {
									profileImageUrl = generateInitialsImage(name);
								} else {
									toast.info(
										$i18n.t(
											'Fingerprint spoofing detected: Unable to use initials as avatar. Defaulting to default profile image.'
										),
										{
											duration: 1000 * 10
										}
									);
								}
							}}>{$i18n.t('Use Initials')}</button
						>
					</div>
				</div>
			</div>
		</div> -->

		<div class="flex space-x-5">
			<div class="flex flex-col">
				<div class="self-center mt-2">
					<button
						class="relative rounded-full dark:bg-gray-700"
						type="button"
						on:click={() => {
							profileImageInputElement.click();
						}}
					>
						<img
							src={profileImageUrl !== '' ? profileImageUrl : generateInitialsImage(name)}
							alt="profile"
							class=" rounded-full size-16 object-cover"
						/>

						<div
							class="absolute flex justify-center rounded-full bottom-0 left-0 right-0 top-0 h-full w-full overflow-hidden bg-gray-700 bg-fixed opacity-0 transition duration-300 ease-in-out hover:opacity-50"
						>
							<div class="my-auto text-gray-100">
								<svg
									xmlns="http://www.w3.org/2000/svg"
									viewBox="0 0 20 20"
									fill="currentColor"
									class="w-5 h-5"
								>
									<path
										d="m2.695 14.762-1.262 3.155a.5.5 0 0 0 .65.65l3.155-1.262a4 4 0 0 0 1.343-.886L17.5 5.501a2.121 2.121 0 0 0-3-3L3.58 13.419a4 4 0 0 0-.885 1.343Z"
									/>
								</svg>
							</div>
						</div>
					</button>
				</div>
			</div>

			<div class="flex-1 flex flex-col self-center">
				<div class="  font-medium mb-1.5">{$i18n.t('Profile Image')}</div>

				<div>
					<button
						class=" text-xs text-center text-gray-800 dark:text-gray-400 rounded-lg px-4 py-1 bg-gray-100 dark:bg-gray-850"
						on:click={async () => {
							if (canvasPixelTest()) {
								profileImageUrl = generateInitialsImage(name);
							} else {
								toast.info(
									$i18n.t(
										'Fingerprint spoofing detected: Unable to use initials as avatar. Defaulting to default profile image.'
									),
									{
										duration: 1000 * 10
									}
								);
							}
						}}>{$i18n.t('Use Initials')}</button
					>

					<button
						class=" text-xs text-center text-gray-800 dark:text-gray-400 rounded-lg px-4 py-1 bg-gray-100 dark:bg-gray-850"
						on:click={async () => {
							const url = await getGravatarUrl($user.email);

							profileImageUrl = url;
						}}>{$i18n.t('Use Gravatar')}</button
					>

					<button
						class=" text-xs text-center text-gray-800 dark:text-gray-400 rounded-lg px-4 py-1 bg-gray-100 dark:bg-gray-850"
						on:click={async () => {
							profileImageUrl = '/user.png';
						}}>{$i18n.t('Remove')}</button
					>
291
292
293
294
				</div>
			</div>
		</div>

Timothy J. Baek's avatar
Timothy J. Baek committed
295
296
297
298
299
300
301
302
303
304
305
306
307
308
		<div class="flex-1">
			<div class="flex flex-col w-full">
				<div class=" mb-1 text-xs text-gray-500">{$i18n.t('Name')}</div>

				<div class="flex-1">
					<input
						class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
						type="text"
						bind:value={name}
						required
					/>
				</div>
			</div>
		</div>
309
310
		<hr class=" dark:border-gray-700 my-4" />
		<UpdatePassword />
Timothy J. Baek's avatar
Timothy J. Baek committed
311
312
313

		<hr class=" dark:border-gray-700 my-4" />

liu.vaayne's avatar
liu.vaayne committed
314
		<div class="flex flex-col gap-4">
Timothy J. Baek's avatar
Timothy J. Baek committed
315
			<div class="justify-between w-full">
liu.vaayne's avatar
liu.vaayne committed
316
				<div class="flex justify-between w-full">
Timothy J. Baek's avatar
Timothy J. Baek committed
317
					<div class="self-center text-xs font-medium">{$i18n.t('JWT Token')}</div>
liu.vaayne's avatar
liu.vaayne committed
318
319
320
321
322
				</div>

				<div class="flex mt-2">
					<div class="flex w-full">
						<input
Timothy J. Baek's avatar
Timothy J. Baek committed
323
							class="w-full rounded-l-lg py-1.5 pl-4 text-sm bg-white dark:text-gray-300 dark:bg-gray-800 outline-none"
liu.vaayne's avatar
liu.vaayne committed
324
325
326
327
							type={showJWTToken ? 'text' : 'password'}
							value={localStorage.token}
							disabled
						/>
Timothy J. Baek's avatar
Timothy J. Baek committed
328

liu.vaayne's avatar
liu.vaayne committed
329
						<button
Timothy J. Baek's avatar
Timothy J. Baek committed
330
							class="px-2 transition rounded-r-lg bg-white dark:bg-gray-800"
liu.vaayne's avatar
liu.vaayne committed
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
							on:click={() => {
								showJWTToken = !showJWTToken;
							}}
						>
							{#if showJWTToken}
								<svg
									xmlns="http://www.w3.org/2000/svg"
									viewBox="0 0 16 16"
									fill="currentColor"
									class="w-4 h-4"
								>
									<path
										fill-rule="evenodd"
										d="M3.28 2.22a.75.75 0 0 0-1.06 1.06l10.5 10.5a.75.75 0 1 0 1.06-1.06l-1.322-1.323a7.012 7.012 0 0 0 2.16-3.11.87.87 0 0 0 0-.567A7.003 7.003 0 0 0 4.82 3.76l-1.54-1.54Zm3.196 3.195 1.135 1.136A1.502 1.502 0 0 1 9.45 8.389l1.136 1.135a3 3 0 0 0-4.109-4.109Z"
										clip-rule="evenodd"
									/>
									<path
										d="m7.812 10.994 1.816 1.816A7.003 7.003 0 0 1 1.38 8.28a.87.87 0 0 1 0-.566 6.985 6.985 0 0 1 1.113-2.039l2.513 2.513a3 3 0 0 0 2.806 2.806Z"
									/>
								</svg>
							{:else}
								<svg
									xmlns="http://www.w3.org/2000/svg"
									viewBox="0 0 16 16"
									fill="currentColor"
									class="w-4 h-4"
								>
									<path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z" />
									<path
										fill-rule="evenodd"
										d="M1.38 8.28a.87.87 0 0 1 0-.566 7.003 7.003 0 0 1 13.238.006.87.87 0 0 1 0 .566A7.003 7.003 0 0 1 1.379 8.28ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
										clip-rule="evenodd"
									/>
								</svg>
							{/if}
						</button>
					</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
368
369

					<button
Timothy J. Baek's avatar
Timothy J. Baek committed
370
						class="ml-1.5 px-1.5 py-1 dark:hover:bg-gray-800 transition rounded-lg"
Timothy J. Baek's avatar
Timothy J. Baek committed
371
						on:click={() => {
liu.vaayne's avatar
liu.vaayne committed
372
373
374
375
376
							copyToClipboard(localStorage.token);
							JWTTokenCopied = true;
							setTimeout(() => {
								JWTTokenCopied = false;
							}, 2000);
Timothy J. Baek's avatar
Timothy J. Baek committed
377
378
						}}
					>
liu.vaayne's avatar
liu.vaayne committed
379
						{#if JWTTokenCopied}
Timothy J. Baek's avatar
Timothy J. Baek committed
380
381
							<svg
								xmlns="http://www.w3.org/2000/svg"
liu.vaayne's avatar
liu.vaayne committed
382
								viewBox="0 0 20 20"
Timothy J. Baek's avatar
Timothy J. Baek committed
383
384
385
386
387
								fill="currentColor"
								class="w-4 h-4"
							>
								<path
									fill-rule="evenodd"
liu.vaayne's avatar
liu.vaayne committed
388
									d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
Timothy J. Baek's avatar
Timothy J. Baek committed
389
390
391
392
393
394
395
396
397
398
399
400
									clip-rule="evenodd"
								/>
							</svg>
						{:else}
							<svg
								xmlns="http://www.w3.org/2000/svg"
								viewBox="0 0 16 16"
								fill="currentColor"
								class="w-4 h-4"
							>
								<path
									fill-rule="evenodd"
liu.vaayne's avatar
liu.vaayne committed
401
402
403
404
405
406
									d="M11.986 3H12a2 2 0 0 1 2 2v6a2 2 0 0 1-1.5 1.937V7A2.5 2.5 0 0 0 10 4.5H4.063A2 2 0 0 1 6 3h.014A2.25 2.25 0 0 1 8.25 1h1.5a2.25 2.25 0 0 1 2.236 2ZM10.5 4v-.75a.75.75 0 0 0-.75-.75h-1.5a.75.75 0 0 0-.75.75V4h3Z"
									clip-rule="evenodd"
								/>
								<path
									fill-rule="evenodd"
									d="M3 6a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1H3Zm1.75 2.5a.75.75 0 0 0 0 1.5h3.5a.75.75 0 0 0 0-1.5h-3.5ZM4 11.75a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 0 1.5h-3.5a.75.75 0 0 1-.75-.75Z"
Timothy J. Baek's avatar
Timothy J. Baek committed
407
408
409
410
411
412
									clip-rule="evenodd"
								/>
							</svg>
						{/if}
					</button>
				</div>
liu.vaayne's avatar
liu.vaayne committed
413
			</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
414
			<div class="justify-between w-full">
liu.vaayne's avatar
liu.vaayne committed
415
				<div class="flex justify-between w-full">
Timothy J. Baek's avatar
Timothy J. Baek committed
416
					<div class="self-center text-xs font-medium">{$i18n.t('API Key')}</div>
liu.vaayne's avatar
liu.vaayne committed
417
				</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
418

liu.vaayne's avatar
liu.vaayne committed
419
				<div class="flex mt-2">
Timothy J. Baek's avatar
Timothy J. Baek committed
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
					{#if APIKey}
						<div class="flex w-full">
							<input
								class="w-full rounded-l-lg py-1.5 pl-4 text-sm bg-white dark:text-gray-300 dark:bg-gray-800 outline-none"
								type={showAPIKey ? 'text' : 'password'}
								value={APIKey}
								disabled
							/>

							<button
								class="px-2 transition rounded-r-lg bg-white dark:bg-gray-800"
								on:click={() => {
									showAPIKey = !showAPIKey;
								}}
							>
								{#if showAPIKey}
									<svg
										xmlns="http://www.w3.org/2000/svg"
										viewBox="0 0 16 16"
										fill="currentColor"
										class="w-4 h-4"
									>
										<path
											fill-rule="evenodd"
											d="M3.28 2.22a.75.75 0 0 0-1.06 1.06l10.5 10.5a.75.75 0 1 0 1.06-1.06l-1.322-1.323a7.012 7.012 0 0 0 2.16-3.11.87.87 0 0 0 0-.567A7.003 7.003 0 0 0 4.82 3.76l-1.54-1.54Zm3.196 3.195 1.135 1.136A1.502 1.502 0 0 1 9.45 8.389l1.136 1.135a3 3 0 0 0-4.109-4.109Z"
											clip-rule="evenodd"
										/>
										<path
											d="m7.812 10.994 1.816 1.816A7.003 7.003 0 0 1 1.38 8.28a.87.87 0 0 1 0-.566 6.985 6.985 0 0 1 1.113-2.039l2.513 2.513a3 3 0 0 0 2.806 2.806Z"
										/>
									</svg>
								{:else}
									<svg
										xmlns="http://www.w3.org/2000/svg"
										viewBox="0 0 16 16"
										fill="currentColor"
										class="w-4 h-4"
									>
										<path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z" />
										<path
											fill-rule="evenodd"
											d="M1.38 8.28a.87.87 0 0 1 0-.566 7.003 7.003 0 0 1 13.238.006.87.87 0 0 1 0 .566A7.003 7.003 0 0 1 1.379 8.28ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
											clip-rule="evenodd"
										/>
									</svg>
								{/if}
							</button>
						</div>
liu.vaayne's avatar
liu.vaayne committed
468
469

						<button
Timothy J. Baek's avatar
Timothy J. Baek committed
470
							class="ml-1.5 px-1.5 py-1 dark:hover:bg-gray-800 transition rounded-lg"
liu.vaayne's avatar
liu.vaayne committed
471
							on:click={() => {
Timothy J. Baek's avatar
Timothy J. Baek committed
472
473
474
475
476
								copyToClipboard(APIKey);
								APIKeyCopied = true;
								setTimeout(() => {
									APIKeyCopied = false;
								}, 2000);
liu.vaayne's avatar
liu.vaayne committed
477
							}}
Timothy J. Baek's avatar
Timothy J. Baek committed
478
						>
Timothy J. Baek's avatar
Timothy J. Baek committed
479
							{#if APIKeyCopied}
liu.vaayne's avatar
liu.vaayne committed
480
481
								<svg
									xmlns="http://www.w3.org/2000/svg"
Timothy J. Baek's avatar
Timothy J. Baek committed
482
									viewBox="0 0 20 20"
liu.vaayne's avatar
liu.vaayne committed
483
484
485
486
487
									fill="currentColor"
									class="w-4 h-4"
								>
									<path
										fill-rule="evenodd"
Timothy J. Baek's avatar
Timothy J. Baek committed
488
										d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
liu.vaayne's avatar
liu.vaayne committed
489
490
491
492
493
494
495
496
497
498
499
500
										clip-rule="evenodd"
									/>
								</svg>
							{:else}
								<svg
									xmlns="http://www.w3.org/2000/svg"
									viewBox="0 0 16 16"
									fill="currentColor"
									class="w-4 h-4"
								>
									<path
										fill-rule="evenodd"
Timothy J. Baek's avatar
Timothy J. Baek committed
501
502
503
504
505
506
										d="M11.986 3H12a2 2 0 0 1 2 2v6a2 2 0 0 1-1.5 1.937V7A2.5 2.5 0 0 0 10 4.5H4.063A2 2 0 0 1 6 3h.014A2.25 2.25 0 0 1 8.25 1h1.5a2.25 2.25 0 0 1 2.236 2ZM10.5 4v-.75a.75.75 0 0 0-.75-.75h-1.5a.75.75 0 0 0-.75.75V4h3Z"
										clip-rule="evenodd"
									/>
									<path
										fill-rule="evenodd"
										d="M3 6a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1H3Zm1.75 2.5a.75.75 0 0 0 0 1.5h3.5a.75.75 0 0 0 0-1.5h-3.5ZM4 11.75a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 0 1.5h-3.5a.75.75 0 0 1-.75-.75Z"
liu.vaayne's avatar
liu.vaayne committed
507
508
509
510
511
512
										clip-rule="evenodd"
									/>
								</svg>
							{/if}
						</button>

Timothy J. Baek's avatar
Timothy J. Baek committed
513
514
515
516
517
518
						<Tooltip content="Create new key">
							<button
								class=" px-1.5 py-1 dark:hover:bg-gray-800transition rounded-lg"
								on:click={() => {
									createAPIKeyHandler();
								}}
liu.vaayne's avatar
liu.vaayne committed
519
							>
Timothy J. Baek's avatar
Timothy J. Baek committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
								<svg
									xmlns="http://www.w3.org/2000/svg"
									fill="none"
									viewBox="0 0 24 24"
									stroke-width="2"
									stroke="currentColor"
									class="size-4"
								>
									<path
										stroke-linecap="round"
										stroke-linejoin="round"
										d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"
									/>
								</svg>
							</button>
						</Tooltip>
					{:else}
						<button
							class="flex gap-1.5 items-center font-medium px-3.5 py-1.5 rounded-lg bg-gray-100/70 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition"
							on:click={() => {
								createAPIKeyHandler();
							}}
						>
							<Plus strokeWidth="2" className=" size-3.5" />
Timothy J. Baek's avatar
Timothy J. Baek committed
544

Timothy J. Baek's avatar
Timothy J. Baek committed
545
							Create new secret key</button
Timothy J. Baek's avatar
Timothy J. Baek committed
546
						>
Timothy J. Baek's avatar
Timothy J. Baek committed
547
					{/if}
liu.vaayne's avatar
liu.vaayne committed
548
				</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
549
550
			</div>
		</div>
551
552
553
554
	</div>

	<div class="flex justify-end pt-3 text-sm font-medium">
		<button
Timothy J. Baek's avatar
Timothy J. Baek committed
555
			class="  px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
556
557
558
559
560
561
562
563
			on:click={async () => {
				const res = await submitHandler();

				if (res) {
					saveHandler();
				}
			}}
		>
Jannik Streidl's avatar
Jannik Streidl committed
564
			{$i18n.t('Save')}
565
566
567
		</button>
	</div>
</div>