Skip to content

Commit

Permalink
feat: add validate of date and get count related on api
Browse files Browse the repository at this point in the history
  • Loading branch information
petchill committed Nov 6, 2023
1 parent adbf88e commit 4577bcc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
3 changes: 1 addition & 2 deletions constants/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const FIRESTORE_DOCUMENT_COLLECTION = 'documents';
export const FIRESTORE_USER_COLLECTION = 'users';
export const IGNORED_PERSONALID = '1111111111111';
export const OFFLINE_DOCUMENTS_COUNT = 205739;
export const WEB_URI = 'https://pension-act.org';
export const WEB_URI = 'https://pension-4all.com';
2 changes: 1 addition & 1 deletion web/src/components/petition.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ul>
</div>
</div>
<div class="bg-base-100 p-[10px] rounded-[2px]">
<div class="bg-base-100 p-[10px] rounded-[4px]">
<SignatureForm />
</div>
</div>
40 changes: 35 additions & 5 deletions web/src/components/signature-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { createForm } from 'felte';
import { reporter, ValidationMessage } from '@felte/reporter-svelte';
import { flatten, parse, ValiError } from 'valibot';
import { date, flatten, parse, ValiError } from 'valibot';
import SignaturePad from 'signature_pad';
import { documentSchema } from '@pension-act/models';
import { submitDocument } from '../utils/firebase';
Expand All @@ -19,16 +19,41 @@
signaturePad.fromData(signaturePad.toData());
});
const dayOptions = [...Array.from({ length: 31 }, (_, i) => i + 1)];
let dayOptions = [...Array.from({ length: 31 }, (_, i) => i + 1)];
const monthOptions = [...Array.from({ length: 12 }, (_, i) => i + 1)];
let monthOptions = [...Array.from({ length: 12 }, (_, i) => i + 1)];
const yearOptions = [
let yearOptions = [
...Array.from({ length: 100 }, (_, i) => new Date().getFullYear() - i),
];
const thisDate = new Date();
let dateValue = {
day: thisDate.getDate(),
month: thisDate.getMonth() + 1,
year: thisDate.getFullYear(),
};
const setDateOptions = () => {
if (dateValue.month === 2) {
if (dateValue.year % 4 === 0) {
dayOptions = [...Array.from({ length: 29 }, (_, i) => i + 1)];
} else {
dayOptions = [...Array.from({ length: 28 }, (_, i) => i + 1)];
}
} else if ([4, 6, 9, 11].includes(dateValue.month)) {
dayOptions = [...Array.from({ length: 30 }, (_, i) => i + 1)];
} else {
dayOptions = [...Array.from({ length: 31 }, (_, i) => i + 1)];
}
if (!dayOptions.includes(dateValue.day)) {
dateValue.day = dayOptions[dayOptions.length - 1];
}
};
$: dateValue, setDateOptions();
const { form, setTouched, setData, data, reset } = createForm({
validate(values) {
try {
Expand All @@ -41,7 +66,9 @@
async onSubmit(values) {
isLoading = true;
try {
console.log(parse(documentSchema, values));
values.day = dateValue.day;
values.month = dateValue.month;
values.year = dateValue.year;
await submitDocument(parse(documentSchema, values));
successDialog.showModal();
clearPad();
Expand Down Expand Up @@ -101,6 +128,7 @@
? 'input-error'
: ''}"
disabled={isLoading}
bind:value={dateValue.day}
name="day"
>
{#each dayOptions as day}
Expand All @@ -121,6 +149,7 @@
: ''}"
disabled={isLoading}
name="month"
bind:value={dateValue.month}
>
{#each monthOptions as month}
<option selected={month === thisDate.getMonth() + 1}
Expand All @@ -143,6 +172,7 @@
: ''}"
disabled={isLoading}
name="year"
bind:value={dateValue.year}
>
{#each yearOptions as year}
<option selected={year === thisDate.getFullYear()}
Expand Down
3 changes: 2 additions & 1 deletion web/src/layouts/main.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import '../styles/fonts.css';
import '../styles/typography.css';
import '../styles/global.css';
import { WEB_URI } from '@pension-act/constants';
---

<html lang="en">
Expand All @@ -28,7 +29,7 @@ import '../styles/global.css';
<script
type="text/partytown"
defer
data-domain="pension-act.com"
data-domain={WEB_URI}
src="https://analytics.punchup.world/js/plausible.js"></script>
</head>

Expand Down
8 changes: 4 additions & 4 deletions web/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import Main from '../layouts/main.astro';
import EventReason from '../components/event-reasons.svelte';
import Welcome from '../components/welcome.svelte';
import TableRegister from '../components/table-register.svelte';
import Partner from '../components/partner.svelte';
import Petition from '../components/petition.svelte';
import Navbar from '../components/navbar.svelte';
import { OFFLINE_DOCUMENTS_COUNT } from '@pension-act/constants';
import Info from '../components/info.svelte';
import { countSubmittedDocuments } from '../utils/firebase';
let documentCount = await countSubmittedDocuments();
---

<script>
Expand Down Expand Up @@ -40,7 +40,7 @@ import Info from '../components/info.svelte';
id="welcome"
class="bg-base-300 min-h-screen flex justify-center items-center relative"
>
<Welcome documentCount={OFFLINE_DOCUMENTS_COUNT} />
<Welcome documentCount={documentCount} />
</section>

<section id="nav" class="bg-primary p-0 w-screen fixed top-0 z-50">
Expand Down

0 comments on commit 4577bcc

Please sign in to comment.