| 
1 | 1 | <script>  | 
2 |  | -	import { PUBLIC_BRAND_NAME, PUBLIC_LOGIN_IMAGE } from '$env/static/public';  | 
 | 2 | +	import { onMount } from 'svelte';  | 
 | 3 | +	import { PUBLIC_BRAND_NAME } from '$env/static/public';  | 
3 | 4 | 	import { Row, Col, Card, CardBody, CardTitle, Table } from '@sveltestrap/sveltestrap';  | 
4 | 5 | 	import Breadcrumb from '$lib/common/Breadcrumb.svelte';  | 
5 | 6 | 	import HeadTitle from '$lib/common/HeadTitle.svelte';  | 
6 |  | -	import { onMount } from 'svelte';  | 
7 |  | -	import { myInfo } from '$lib/services/auth-service';  | 
 | 7 | +	import FileDropZone from '$lib/common/FileDropZone.svelte';  | 
 | 8 | +	import { myInfo, uploadUserAvatar } from '$lib/services/auth-service';  | 
8 | 9 | 	import { _ } from 'svelte-i18n';  | 
9 |  | -
  | 
 | 10 | +	import { userStore } from '$lib/helpers/store';  | 
 | 11 | +	import { PUBLIC_SERVICE_URL } from '$env/static/public';  | 
 | 12 | +	import { buildUrl } from '$lib/helpers/utils/common';  | 
 | 13 | +	  | 
10 | 14 | 	/** @type {import('$types').UserModel} */  | 
11 | 15 | 	let currentUser;  | 
12 | 16 | 	let isLoading = false;  | 
 | 17 | +
  | 
13 | 18 | 	onMount(async () => {  | 
14 | 19 | 		isLoading = true;  | 
15 | 20 | 		await myInfo()  | 
 | 
20 | 25 | 				isLoading = false;  | 
21 | 26 | 			});  | 
22 | 27 | 	});  | 
 | 28 | +
  | 
 | 29 | +	/** @param {any} e */  | 
 | 30 | +    async function handleFileDrop(e) {  | 
 | 31 | +        const { acceptedFiles } = e.detail;  | 
 | 32 | +		const file = acceptedFiles[0];  | 
 | 33 | +		if (!!!file) return;  | 
 | 34 | +
  | 
 | 35 | +		await uploadUserAvatar(file);  | 
 | 36 | +		window.location.reload();  | 
 | 37 | +    }  | 
 | 38 | +
  | 
 | 39 | +	/** @param {any} e */  | 
 | 40 | +	function handleAvatarLoad(e) {  | 
 | 41 | +		e.target.src = 'images/users/user-dummy.jpg';  | 
 | 42 | +	}  | 
23 | 43 | </script>  | 
24 | 44 | 
 
  | 
25 | 45 | <HeadTitle title="{$_('My Profile')}" />  | 
 | 
41 | 61 | 				<Row>  | 
42 | 62 | 					<Col sm={4}>  | 
43 | 63 | 						<div class="avatar-md profile-user-wid mb-4">  | 
44 |  | -							<img  | 
45 |  | -								src="images/users/user-dummy.jpg"  | 
46 |  | -								alt="avatar"  | 
47 |  | -								class="img-thumbnail rounded-circle"  | 
48 |  | -							/>  | 
 | 64 | +							<FileDropZone  | 
 | 65 | +								accept="image/*"  | 
 | 66 | +								disableDefaultStyles  | 
 | 67 | +								containerStyles={'width: 100%; height: 100%;'}  | 
 | 68 | +								noDrag  | 
 | 69 | +								multiple={false}  | 
 | 70 | +								fileLimit={1}  | 
 | 71 | +								on:drop={e => handleFileDrop(e)}  | 
 | 72 | +							>  | 
 | 73 | +								<img  | 
 | 74 | +									src={`${buildUrl(PUBLIC_SERVICE_URL, currentUser?.avatar || '').href}?access_token=${$userStore?.token}`}  | 
 | 75 | +									alt=""  | 
 | 76 | +									class="img-thumbnail rounded-circle"  | 
 | 77 | +									style="width: 100%; height: 100%;"  | 
 | 78 | +									on:error={e => handleAvatarLoad(e)}  | 
 | 79 | +								/>  | 
 | 80 | +							</FileDropZone>  | 
49 | 81 | 						</div>  | 
50 | 82 | 						<h5 class="font-size-15 text-truncate">{currentUser?.full_name}</h5>  | 
51 | 83 | 						<p class="text-muted mb-0 text-truncate">{currentUser?.role ?? 'Role: N/A'}</p>  | 
 | 
0 commit comments