diff --git a/src/routes/console/[project]/users/user/[user]/index.svelte b/src/routes/console/[project]/users/user/[user]/index.svelte
index f71d15f80..5b2f691ee 100644
--- a/src/routes/console/[project]/users/user/[user]/index.svelte
+++ b/src/routes/console/[project]/users/user/[user]/index.svelte
@@ -2,7 +2,7 @@
import { toLocaleDate } from '$lib/helpers/date';
import { Avatar, Card } from '$lib/components';
import { Pill } from '$lib/elements';
- import { Button, InputText, InputEmail, InputPassword } from '$lib/elements/forms';
+ import { Button, InputText, InputEmail, InputPassword, Helper } from '$lib/elements/forms';
import { Container } from '$lib/layout';
import { sdkForProject } from '$lib/stores/sdk';
import { addNotification } from '$lib/stores/notifications';
@@ -11,21 +11,35 @@
import { user } from './store';
let showDelete = false;
+ let showError: false | 'name' | 'email' | 'password' = false;
+ let errorMessage = 'Something went wrong';
+ let errorType: 'error' | 'warning' | 'success' = 'error';
let userName = null;
let userEmail = null;
- let oldPw = null;
- let newPw = null;
+ let repeatPassword = null;
+ let newPassword = null;
const getAvatar = (name: string) =>
sdkForProject.avatars.getInitials(name, 128, 128).toString();
+ function addError(location: false | 'name' | 'email' | 'password', message: string, type) {
+ showError = location;
+ errorMessage = message;
+ errorType = type;
+ setTimeout(() => {
+ showError = false;
+ }, 6000);
+ }
+
async function updateVerification() {
try {
- await sdkForProject.users.updateVerification($user.$id, true);
- $user.emailVerification = true;
+ await sdkForProject.users.updateVerification($user.$id, !$user.emailVerification);
+ $user.emailVerification = !$user.emailVerification;
addNotification({
- message: 'The account has been verified',
- type: 'success'
+ message: `The account has been ${
+ $user.emailVerification ? 'verified' : 'unverified'
+ }`,
+ type: $user.emailVerification ? 'success' : 'info'
});
} catch (error) {
addNotification({
@@ -39,7 +53,7 @@
await sdkForProject.users.updateStatus($user.$id, !$user.status);
$user.status = !$user.status;
addNotification({
- message: `The account has been ${$user.status ? 'unlocked' : 'blocked'}`,
+ message: `The account has been ${$user.status ? 'unblocked' : 'blocked'}`,
type: `${$user.status ? 'success' : 'error'}`
});
} catch (error) {
@@ -58,10 +72,7 @@
type: 'success'
});
} catch (error) {
- addNotification({
- message: error.message,
- type: 'error'
- });
+ addError('name', error.message, 'error');
}
}
async function updateEmail() {
@@ -73,26 +84,22 @@
type: 'success'
});
} catch (error) {
- addNotification({
- message: error.message,
- type: 'error'
- });
+ addError('email', error.message, 'error');
}
}
async function updatePassword() {
- try {
- await sdkForProject.users.updatePassword($user.$id, newPw);
- $user.email = userEmail;
- addNotification({
- message: 'Password has been updated',
- type: 'success'
- });
- } catch (error) {
- addNotification({
- message: error.message,
- type: 'error'
- });
- }
+ if (newPassword === repeatPassword)
+ try {
+ await sdkForProject.users.updatePassword($user.$id, newPassword);
+ $user.email = userEmail;
+ addNotification({
+ message: 'Password has been updated',
+ type: 'success'
+ });
+ } catch (error) {
+ addError('password', error.message, 'error');
+ }
+ else addError('password', "Passwords don't match", 'error');
}
@@ -110,7 +117,6 @@
{#if !$user.status}
Joined on {toLocaleDate($user.registration)}
@@ -118,11 +124,9 @@