Skip to content

Commit

Permalink
reduce number of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
MaHaWo committed Oct 14, 2024
1 parent 22376cd commit 0eff1dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
51 changes: 21 additions & 30 deletions frontend/src/lib/components/UserForgotPassword.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { Button, Card, Heading, Input } from 'flowbite-svelte';
import { _ } from 'svelte-i18n';
const heading = $_('user.forgotPw.heading');
const maildata = {
component: Input,
type: 'text',
Expand All @@ -16,12 +15,8 @@
placeholder: $_('user.forgotPw.placeholder')
}
};
const successButtonLabel: string = $_('user.forgotPw.success');
const pendingButtonLabel: string = $_('user.forgotPw.pending');
const mailSentMessage: string = $_('user.forgotPw.mailSentMessage');
const alertTitle: string = $_('user.forgotPw.alertTitle');
let alertMessage: string = $_('user.forgotPw.alertMessage');
let alertMessage: string = $_('user.forgotPw.formatError');
let valid: boolean = true;
let showAlert: boolean = !valid;
let showSuccess: boolean = false;
Expand All @@ -36,33 +31,29 @@
}
async function submitData(mailstring: string): Promise<void> {
try {
const data = {
body: {
email: mailstring
},
throwOnError: true
};
const { response, error } = await resetForgotPassword(data);
const data = {
body: {
email: mailstring
},
throwOnError: true
};
if (error) {
console.log('error: ', error);
throw Error(error);
} else {
console.log('successful transmission, response status: ', response.status);
await resetForgotPassword(data)
.then((returned) => {
console.log('successful transmission, response status: ', returned.response.status);
showSuccess = true;
}
} catch (error) {
console.log(error);
showAlert = true;
alertMessage = $_('user.forgotPw.sendError');
}
})
.catch((error) => {
console.log(error);
showAlert = true;
alertMessage = $_('user.forgotPw.sendError');
});
}
</script>

{#if showAlert}
<AlertMessage
title={alertTitle}
title={$_('user.forgotPw.alertTitle')}
message={alertMessage}
lastpage={`${base}/userLand/lostPassword`}
onclick={() => {
Expand All @@ -75,7 +66,7 @@
<Heading
tag="h3"
class="m-2 p-2 text-center font-bold tracking-tight text-gray-700 dark:text-gray-400"
>{heading}</Heading
>{$_('user.forgotPw.heading')}</Heading
>
{#if showSuccess === false}
<div class="m-2 mx-auto w-full flex-col space-y-6 p-2">
Expand All @@ -95,19 +86,19 @@
if (valid) {
submitData(maildata.value);
}
}}>{pendingButtonLabel}</Button
}}>{$_('user.forgotPw.pending')}</Button
>
</div>
{:else}
<div class="m-2 flex w-full items-center justify-center p-2">
<p>{mailSentMessage}</p>
<p>{$_('user.forgotPw.mailSentMessage')}</p>
</div>
<div class="m-2 flex w-full items-center justify-center p-2">
<Button
size="md"
on:click={(event) => {
goto(`/${base}`);
}}>{successButtonLabel}</Button
}}>{$_('user.forgotPw.success')}</Button
>
</div>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"success": "Zurück zur Startseite",
"pending": "Absenden",
"alertTitle": "Fehler",
"alertMessage": "Die angegebene email Adresse hat ein falsches Format",
"formatError": "Die angegebene email Adresse hat ein falsches Format",
"mailSentMessage": "Bitte überprüfen sie ihr E-Mail Postfach",
"sendError": "Beim Senden der Daten ist ein Fehler aufgetreten. Bitte versuchen sie es erneut"
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"success": "Back to home",
"pending": "Send",
"alertTitle": "Error",
"alertMessage": "The given e-mail adress has a wrong format.",
"formatError": "The given e-mail adress has a wrong format.",
"mailSentMessage": "Please check your e-mail inbox",
"sendError": "An error occured while sending the data. Please try again."
}
Expand Down

0 comments on commit 0eff1dd

Please sign in to comment.