Skip to content

Commit

Permalink
feat: use Thai in column and sheet name, upgrade sheethuahua to v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Th1nkK1D committed Nov 21, 2024
1 parent 9316693 commit 69cae3c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 39 deletions.
2 changes: 1 addition & 1 deletion e-initiative.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
previewImageUrl: 'https://wevisdemo.github.io/e-initiative-template/og.png',
},
petition: {
endDate: new Date('2024-10-10 GMT+7'),
endDate: new Date('2030-10-10 GMT+7'),
expectedSignatures: 10000,
offline: {
formUrl: 'petition-form.pdf',
Expand Down
24 changes: 19 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"firebase": "^10.12.2",
"pdf-lib": "^1.17.1",
"scrollama": "^3.2.0",
"sheethuahua": "^2.0.0",
"sheethuahua": "^3.1.0",
"signature_pad": "^5.0.1"
},
"devDependencies": {
Expand Down
27 changes: 18 additions & 9 deletions src/models/document.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import type { Timestamp } from 'firebase/firestore';
import { Table, Column, type RowType } from 'sheethuahua';
import {
Object,
Column,
type StaticDecode,
asString,
asOneOf,
} from 'sheethuahua';

export const MAX_LOCATION_LENGTH = 20;

export const documentsTable = Table({
location: Column.String({ minLength: 1, maxLength: MAX_LOCATION_LENGTH }),
citizenId: Column.String({ minLength: 13, maxLength: 13 }),
prefix: Column.OneOf(['นาย', 'นาง', 'นางสาว']),
firstname: Column.String({ minLength: 1 }),
lastname: Column.String({ minLength: 1 }),
signature: Column.String({ minLength: 1 }),
export const documentsTable = Object({
location: Column(
'location',
asString({ minLength: 1, maxLength: MAX_LOCATION_LENGTH }),
),
citizenId: Column('citizenId', asString({ minLength: 13, maxLength: 13 })),
prefix: Column('prefix', asOneOf(['นาย', 'นาง', 'นางสาว'])),
firstname: Column('firstname', asString({ minLength: 1 })),
lastname: Column('lastname', asString({ minLength: 1 })),
signature: Column('signature', asString({ minLength: 1 })),
});

export type FormDocument = RowType<typeof documentsTable>;
export type FormDocument = StaticDecode<typeof documentsTable>;

export interface SubmittedDocument extends FormDocument {
uid: string;
Expand Down
18 changes: 9 additions & 9 deletions src/models/location.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Table, Column, type RowType } from 'sheethuahua';
import { Object, Column, type StaticDecode, asString } from 'sheethuahua';

export const locationTable = Table('locations', {
province: Column.String(),
name: Column.String(),
openingTime: Column.OptionalString(),
phone: Column.OptionalString(),
address: Column.OptionalString(),
mapUrl: Column.OptionalString(),
export const locationTable = Object({
province: Column('จังหวัด*', asString()),
name: Column('ชื่อสถานที่*', asString()),
openingTime: Column('เวลาเปิดทำการ', asString().optional()),
phone: Column('เบอร์โทรศัพท์', asString().optional()),
address: Column('ที่อยู่', asString().optional()),
mapUrl: Column('ลิงก์ไป Google Maps', asString().optional()),
});

export type Location = RowType<typeof locationTable>;
export type Location = StaticDecode<typeof locationTable>;
16 changes: 11 additions & 5 deletions src/models/offline-signature.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Table, Column, type RowType } from 'sheethuahua';
import {
Object,
Column,
type StaticDecode,
asDate,
asNumber,
} from 'sheethuahua';

export const offlineSignatureTable = Table('offline-signature', {
date: Column.Date(),
count: Column.Number(),
export const offlineSignatureTable = Object({
date: Column('วันที่*', asDate()),
count: Column('จำนวนคนที่ลงชื่อ*', asNumber()),
});

export type OfflineSignature = RowType<typeof offlineSignatureTable>;
export type OfflineSignature = StaticDecode<typeof offlineSignatureTable>;
14 changes: 5 additions & 9 deletions src/utils/sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ import Config from '../../e-initiative.config.mjs';
import { offlineSignatureTable } from '../models/offline-signature';
import { locationTable } from '../models/location';

const sheets = Spreadsheet(Config.sheets?.id || '', [
offlineSignatureTable,
locationTable,
]);
const sheets = Spreadsheet(Config.sheets?.id || '');

export async function countOfflineSignatures() {
return (await sheets.get('offline-signature')).reduce(
(sum, { count }) => sum + count,
0,
);
return (
await sheets.get('จำนวนคนลงชื่อแบบออฟไลน์', offlineSignatureTable)
).reduce((sum, { count }) => sum + count, 0);
}

export async function getLocations() {
const locations = await sheets.get('locations');
const locations = await sheets.get('จุดลงชื่อแบบออฟไลน์', locationTable);
const uniqueProvinces = [
...new Set(locations.map(({ province }) => province)),
].sort((a, z) => a.localeCompare(z));
Expand Down

0 comments on commit 69cae3c

Please sign in to comment.