Merge pull request #131 from EETagent/frontend_ui_fixes

Frontend UI fixes
This commit is contained in:
Vojtěch Jungmann 2023-01-12 21:14:59 +01:00 committed by GitHub
commit acf6a8e456
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 11 deletions

View file

@ -35,6 +35,7 @@
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@zerodevx/svelte-toast": "^1.0.0-rc.1",
"axios": "^1.2.2", "axios": "^1.2.2",
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"filedrop-svelte": "^0.1.2", "filedrop-svelte": "^0.1.2",

View file

@ -1,6 +1,9 @@
lockfileVersion: '6.0' lockfileVersion: '6.0'
dependencies: dependencies:
'@zerodevx/svelte-toast':
specifier: ^1.0.0-rc.1
version: 1.0.0-rc.1
axios: axios:
specifier: ^1.2.2 specifier: ^1.2.2
version: 1.2.2 version: 1.2.2
@ -711,6 +714,10 @@ packages:
eslint-visitor-keys: 3.3.0 eslint-visitor-keys: 3.3.0
dev: true dev: true
/@zerodevx/svelte-toast@1.0.0-rc.1:
resolution: {integrity: sha512-KEZUWeFg1MLlHVssx94ZWWKDBOlQUznTH7xsfZ3uPSYbD5NMO8jDEUGiDNiJ3aKpwiabGvZgG7NKJLFK0q/KYg==}
dev: false
/abab@2.0.6: /abab@2.0.6:
resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==} resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==}
dev: false dev: false

View file

@ -18,6 +18,7 @@
<style lang="postcss"> <style lang="postcss">
input { input {
@apply hover:cursor-pointer;
@apply bg-sspsBlue hover:bg-sspsBlueDark @apply bg-sspsBlue hover:bg-sspsBlueDark
@apply @apply rounded-lg p-3 text-xl font-semibold @apply @apply rounded-lg p-3 text-xl font-semibold
text-white transition-colors duration-300; text-white transition-colors duration-300;

View file

@ -14,6 +14,7 @@
import TelephoneField from '$lib/components/textfield/TelephoneField.svelte'; import TelephoneField from '$lib/components/textfield/TelephoneField.svelte';
import TextField from '$lib/components/textfield/TextField.svelte'; import TextField from '$lib/components/textfield/TextField.svelte';
import type { PageData } from './$types'; import type { PageData } from './$types';
import { SvelteToast, toast } from '@zerodevx/svelte-toast';
import { createForm } from 'svelte-forms-lib'; import { createForm } from 'svelte-forms-lib';
import type { Writable } from 'svelte/store'; import type { Writable } from 'svelte/store';
@ -199,7 +200,14 @@
values.candidate.birthdate values.candidate.birthdate
) )
) { ) {
alert('Rodné číslo neodpovídá oficiální specifikaci či datumu narození'); // TODO: alerts // alert('Rodné číslo neodpovídá oficiální specifikaci či datumu narození'); // TODO: alerts
toast.push('Rodné číslo neodpovídá oficiální specifikaci či datumu narození', {
theme: {
'--toastColor': 'mintcream',
'--toastBackground': '#b91c1c',
'--toastBarBackground': '#7f1d1d'
}
})
throw new Error('Rodné číslo neodpovídá datumu narození'); throw new Error('Rodné číslo neodpovídá datumu narození');
} }
} }
@ -332,6 +340,7 @@
</script> </script>
<SplitLayout> <SplitLayout>
<SvelteToast></SvelteToast>
<div class="form relative"> <div class="form relative">
<div class="bottom-3/12 absolute flex w-full flex-col md:h-auto"> <div class="bottom-3/12 absolute flex w-full flex-col md:h-auto">
<div class="<md:h-24 <md:w-24 mb-4 h-32 w-32 self-center"> <div class="<md:h-24 <md:w-24 mb-4 h-32 w-32 self-center">

View file

@ -6,11 +6,13 @@
import { page } from '$app/stores'; import { page } from '$app/stores';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { apiLogin } from '$lib/@api/candidate'; import { apiLogin } from '$lib/@api/candidate';
import { SvelteToast, toast } from '@zerodevx/svelte-toast';
let applicationId = Number($page.params.code); let applicationId = Number($page.params.code);
let codeValueMobile: string = ''; let codeValueMobile: string = '';
let codeValueArray: Array<string> = []; let codeValueArray: Array<string> = [];
let codeElementArray: Array<HTMLInputElement> = []; let codeElementArray: Array<HTMLInputElement> = [];
let isError: boolean = false;
$: { $: {
codeValueMobile = codeValueMobile.toUpperCase(); codeValueMobile = codeValueMobile.toUpperCase();
@ -18,7 +20,7 @@
console.log(codeValueArray); console.log(codeValueArray);
} }
const inputDesktopOnKeyDown = (index: number, e: KeyboardEvent) => { const inputDesktopOnKeyDown = async (index: number, e: KeyboardEvent) => {
if (e.key === 'Backspace') { if (e.key === 'Backspace') {
codeValueArray[index] = ''; codeValueArray[index] = '';
if (codeElementArray[index - 1]) { if (codeElementArray[index - 1]) {
@ -34,31 +36,45 @@
} }
} }
codeValueMobile = codeValueArray.join(''); codeValueMobile = codeValueArray.join('');
if (codeValueArray.filter((item) => item !== '').length === 12) {
await submit();
} else {
isError = false;
}
}; };
$: if (codeValueArray.length === 12) {
submit();
}
const submit = async () => { const submit = async () => {
console.log('submitting: ', codeValueArray);
try { try {
await apiLogin({ applicationId, password: codeValueMobile }); await apiLogin({ applicationId, password: codeValueMobile });
goto('/dashboard'); goto('/dashboard');
} catch (e) { } catch (e) {
console.error(e); console.error(e);
toast.push('Neplatné heslo!', {
theme: {
'--toastColor': 'mintcream',
'--toastBackground': '#b91c1c',
'--toastBarBackground': '#7f1d1d'
}
});
isError = true;
} }
// alert('ApplicationId: ' + applicationId + '; Password: ' + codeValueMobile);
}; };
const onPaste = (e: ClipboardEvent) => { const onPaste = async (e: ClipboardEvent) => {
e.preventDefault(); e.preventDefault();
const text = e.clipboardData?.getData('text/plain'); const text = e.clipboardData?.getData('text/plain').slice(0, 12);
if (text) { if (text) {
codeValueMobile = text; codeValueMobile = text;
codeValueArray = text.split('');
} }
for (const el of codeElementArray) { for (const el of codeElementArray) {
el.blur(); el.blur();
} }
if (codeValueArray.filter((item) => item !== '').length === 12) {
await submit();
}
}; };
onMount(() => { onMount(() => {
@ -77,11 +93,18 @@
<FullLayout> <FullLayout>
<div class="modal"> <div class="modal">
<img class="mx-auto" src={woman} alt="" /> <img class="mx-auto" src={woman} alt="" />
<SvelteToast />
<div class="flex items-center justify-center"> <div class="flex items-center justify-center">
<input bind:value={codeValueMobile} type="text" class="codeInputMobile" /> <input
class:error={isError}
bind:value={codeValueMobile}
type="text"
class="codeInputMobile"
/>
{#each [1, 2, 3, 4] as value} {#each [1, 2, 3, 4] as value}
<input <input
class="codeInputDesktop" class="codeInputDesktop"
class:error={isError}
bind:this={codeElementArray[value - 1]} bind:this={codeElementArray[value - 1]}
bind:value={codeValueArray[value - 1]} bind:value={codeValueArray[value - 1]}
on:keydown={(e) => inputDesktopOnKeyDown(value - 1, e)} on:keydown={(e) => inputDesktopOnKeyDown(value - 1, e)}
@ -93,6 +116,7 @@
{#each [5, 6, 7, 8] as value} {#each [5, 6, 7, 8] as value}
<input <input
class="codeInputDesktop" class="codeInputDesktop"
class:error={isError}
bind:this={codeElementArray[value - 1]} bind:this={codeElementArray[value - 1]}
bind:value={codeValueArray[value - 1]} bind:value={codeValueArray[value - 1]}
on:keydown={(e) => inputDesktopOnKeyDown(value - 1, e)} on:keydown={(e) => inputDesktopOnKeyDown(value - 1, e)}
@ -104,6 +128,7 @@
{#each [9, 10, 11, 12] as value} {#each [9, 10, 11, 12] as value}
<input <input
class="codeInputDesktop" class="codeInputDesktop"
class:error={isError}
bind:this={codeElementArray[value - 1]} bind:this={codeElementArray[value - 1]}
bind:value={codeValueArray[value - 1]} bind:value={codeValueArray[value - 1]}
on:keydown={(e) => inputDesktopOnKeyDown(value - 1, e)} on:keydown={(e) => inputDesktopOnKeyDown(value - 1, e)}
@ -120,6 +145,9 @@
</FullLayout> </FullLayout>
<style lang="postcss"> <style lang="postcss">
.error {
@apply border-red-700;
}
.modal { .modal {
@apply flex flex-col items-center justify-center; @apply flex flex-col items-center justify-center;
@apply mx-auto my-auto; @apply mx-auto my-auto;
@ -142,6 +170,6 @@
.codeInputDesktop { .codeInputDesktop {
@apply hidden; @apply hidden;
@apply mr-1 md:mr-2; @apply mr-1 md:mr-2;
@apply sm:h-15 2xl:w-18 2xl:h-22 sm:w-12 sm:text-xl md:block md:h-20 md:w-16 md:text-4xl xl:h-20 xl:w-16 xl:p-0; @apply sm:h-15 2xl:w-18 2xl:h-22 sm:w-12 sm:text-xl md:block md:h-20 md:w-16 md:text-4xl xl:h-20 xl:w-16 xl:p-0 xl:text-2xl;
} }
</style> </style>