2025-11-01 15:49:29 +01:00
|
|
|
<script lang="ts">
|
2025-11-24 01:00:50 +01:00
|
|
|
import { onMount, untrack } from 'svelte';
|
2023-08-02 19:35:27 +01:00
|
|
|
import { goto } from '$app/navigation';
|
2025-11-24 01:00:50 +01:00
|
|
|
import { resolve } from '$app/paths';
|
|
|
|
|
import { page } from '$app/state';
|
2023-08-02 19:35:27 +01:00
|
|
|
import TextField from '$lib/components/Form/TextField.svelte';
|
|
|
|
|
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
2025-11-24 01:00:50 +01:00
|
|
|
import { getConfirmPasswordError } from '$lib/utils/functions/validator';
|
2023-08-02 19:35:27 +01:00
|
|
|
import AuthUI from '$lib/components/AuthUI/index.svelte';
|
2025-11-24 01:00:50 +01:00
|
|
|
import { resetApi } from '$lib/features/auth/api/reset.svelte';
|
|
|
|
|
import type { TResetPasswordForm } from '$lib/features/auth/utils/types';
|
|
|
|
|
import { snackbar } from '$lib/components/Snackbar/store';
|
2022-12-03 22:45:01 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
let fields: TResetPasswordForm = $state({
|
|
|
|
|
password: '',
|
|
|
|
|
confirmPassword: '',
|
|
|
|
|
token: ''
|
|
|
|
|
});
|
2022-12-03 22:45:01 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
const isSubmitDisabled = $derived!!(
|
|
|
|
|
fields.password && fields.confirmPassword && fields.password !== fields.confirmPassword
|
|
|
|
|
);
|
|
|
|
|
const token = $derived(new URLSearchParams(page.url.search).get('token'));
|
2025-11-01 15:49:29 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
onMount(() => {
|
|
|
|
|
if (token) return;
|
2022-12-03 22:45:01 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
snackbar.error('Invalid Token');
|
2022-12-03 22:45:01 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
goto(resolve('/login', {}));
|
|
|
|
|
}, 2000);
|
|
|
|
|
});
|
2022-12-03 22:45:01 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
function setConfirmPasswordError(fields: TResetPasswordForm) {
|
2025-11-01 15:49:29 +01:00
|
|
|
untrack(() => {
|
2025-11-24 01:00:50 +01:00
|
|
|
const errors = { ...resetApi.errors };
|
|
|
|
|
errors.confirmPassword = getConfirmPasswordError(fields) ?? '';
|
|
|
|
|
resetApi.setError(errors);
|
2025-11-01 15:49:29 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
setConfirmPasswordError(fields);
|
|
|
|
|
});
|
2022-12-03 22:45:01 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
2025-11-24 01:00:50 +01:00
|
|
|
<title>Reset Password - ClassroomIO</title>
|
2022-12-03 22:45:01 +01:00
|
|
|
</svelte:head>
|
|
|
|
|
|
|
|
|
|
<AuthUI
|
|
|
|
|
isLogin={false}
|
2025-11-24 01:00:50 +01:00
|
|
|
handleSubmit={() => resetApi.submit({ ...fields, token: token ?? '' })}
|
2022-12-03 22:45:01 +01:00
|
|
|
showOnlyContent={true}
|
2025-11-24 01:00:50 +01:00
|
|
|
isLoading={resetApi.isLoading}
|
2022-12-03 22:45:01 +01:00
|
|
|
showLogo={true}
|
|
|
|
|
>
|
|
|
|
|
<div class="mt-4 w-full">
|
2025-11-01 15:49:29 +01:00
|
|
|
<h3 class="my-3 text-xl font-semibold dark:text-white">New Password</h3>
|
|
|
|
|
<p class="mb-6 text-sm dark:text-white">Enter your new password details</p>
|
2022-12-03 22:45:01 +01:00
|
|
|
<TextField
|
|
|
|
|
label="Your Password"
|
|
|
|
|
bind:value={fields.password}
|
|
|
|
|
type="password"
|
|
|
|
|
placeholder="************"
|
|
|
|
|
className="mb-6"
|
|
|
|
|
inputClassName="w-full"
|
2025-11-24 01:00:50 +01:00
|
|
|
isDisabled={resetApi.isLoading}
|
|
|
|
|
errorMessage={resetApi.errors.password}
|
|
|
|
|
helperMessage="Password must be more than 8 characters"
|
2022-12-03 22:45:01 +01:00
|
|
|
isRequired
|
|
|
|
|
/>
|
|
|
|
|
<TextField
|
|
|
|
|
label="Confirm Password"
|
|
|
|
|
bind:value={fields.confirmPassword}
|
|
|
|
|
type="password"
|
|
|
|
|
placeholder="************"
|
|
|
|
|
className="mb-6"
|
|
|
|
|
inputClassName="w-full"
|
2025-11-24 01:00:50 +01:00
|
|
|
isDisabled={resetApi.isLoading}
|
|
|
|
|
errorMessage={resetApi.errors.confirmPassword}
|
2022-12-03 22:45:01 +01:00
|
|
|
isRequired
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
<div class="my-4 flex w-full items-center justify-end">
|
2022-12-03 22:45:01 +01:00
|
|
|
<PrimaryButton
|
|
|
|
|
label="Reset Password"
|
|
|
|
|
type="submit"
|
|
|
|
|
className="sm:w-full w-full"
|
2025-11-24 01:00:50 +01:00
|
|
|
isDisabled={isSubmitDisabled || resetApi.isLoading}
|
|
|
|
|
isLoading={resetApi.isLoading}
|
2022-12-03 22:45:01 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</AuthUI>
|