Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelSiidorow committed Jan 23, 2025
1 parent e5e3e00 commit 82c4872
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 62 deletions.
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"frail_fine_fish_chop": "Last name",
"lofty_patient_squid_drop": "Home municipality",
"light_frail_poodle_enrich": "Non-membership emails",
"livid_trite_thrush_animate": "The guild is allowed to email me things not related to my membership (e.g. weekly mails)"
"livid_trite_thrush_animate": "The guild is allowed to email me things not related to my membership (e.g. weekly mails)",
"each_strong_butterfly_seek": "Admin panel"
}
3 changes: 2 additions & 1 deletion messages/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"frail_fine_fish_chop": "Sukunimi",
"lofty_patient_squid_drop": "Kotikunta",
"light_frail_poodle_enrich": "Jäsenyyteen liittymättömät sähköpostit",
"livid_trite_thrush_animate": "Kilta saa lähettää sähköpostia jäsenyyteeni liittymättömistä asioista (esim. viikkotiedote)"
"livid_trite_thrush_animate": "Kilta saa lähettää sähköpostia jäsenyyteeni liittymättömistä asioista (esim. viikkotiedote)",
"each_strong_butterfly_seek": "Hallintapaneeli"
}
5 changes: 3 additions & 2 deletions src/lib/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const PAGES = {
"/": `/`,
"/sign-in": `/sign-in`,
"/sign-in/email": `/sign-in/email`,
"/sign-out": `/sign-out`
"/sign-out": `/sign-out`,
"/admin/memberships": `/admin/memberships`
}

/**
Expand Down Expand Up @@ -137,7 +138,7 @@ export function route<T extends keyof AllTypes>(key: T, ...params: any[]): strin
* ```
*/
export type KIT_ROUTES = {
PAGES: { '/': never, '/sign-in': never, '/sign-in/email': never, '/sign-out': never }
PAGES: { '/': never, '/sign-in': never, '/sign-in/email': never, '/sign-out': never, '/admin/memberships': never }
SERVERS: Record<string, never>
ACTIONS: { 'default /': never, 'default /sign-in': never, 'verify /sign-in/email': never, 'resend /sign-in/email': never, 'logout /sign-out': never }
LINKS: Record<string, never>
Expand Down
7 changes: 7 additions & 0 deletions src/lib/components/ui/separator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Root from "./separator.svelte";

export {
Root,
//
Root as Separator,
};
22 changes: 22 additions & 0 deletions src/lib/components/ui/separator/separator.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script lang="ts">
import { Separator as SeparatorPrimitive } from "bits-ui";
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
orientation = "horizontal",
...restProps
}: SeparatorPrimitive.RootProps = $props();
</script>

<SeparatorPrimitive.Root
bind:ref
class={cn(
"bg-border shrink-0",
orientation === "horizontal" ? "h-[1px] w-full" : "min-h-full w-[1px]",
className
)}
{orientation}
{...restProps}
/>
1 change: 1 addition & 0 deletions src/lib/server/auth/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export async function validateSessionToken(token: string) {
lastName: table.user.lastName,
homeMunicipality: table.user.homeMunicipality,
isAllowedEmails: table.user.isAllowedEmails,
isAdmin: table.user.isAdmin,
},
session: table.session,
})
Expand Down
38 changes: 37 additions & 1 deletion src/lib/server/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { boolean, pgTable, text, timestamp } from "drizzle-orm/pg-core";
import { boolean, integer, pgEnum, pgTable, text, timestamp } from "drizzle-orm/pg-core";
import * as z from "zod";

export const user = pgTable("user", {
id: text("id").primaryKey(),
Expand All @@ -25,6 +26,41 @@ export const emailOTP = pgTable("email_otp", {
expiresAt: timestamp("expires_at", { withTimezone: true, mode: "date" }).notNull(),
});

export const membership = pgTable("membership", {
id: text("id").primaryKey(),
type: text("type").notNull(),
startTime: timestamp("start_time", { withTimezone: true, mode: "date" }).notNull(),
endTime: timestamp("end_time", { withTimezone: true, mode: "date" }).notNull(),
priceCents: integer("price").notNull().default(0),
});

export const memberStatusEnum = pgEnum("member_status", [
"awaiting_payment",
"awaiting_approval",
"active",
"expired",
"cancelled",
]);

export const memberStatusEnumSchema = z.enum(memberStatusEnum.enumValues);

export const member = pgTable("member", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => user.id),
membershipId: text("membership_id")
.notNull()
.references(() => membership.id),
status: memberStatusEnum("status").notNull(),
});

export type Member = typeof member.$inferSelect;

export type MemberStatus = z.infer<typeof memberStatusEnumSchema>;

export type Membership = typeof membership.$inferSelect;

export type EmailOTP = typeof emailOTP.$inferSelect;

export type Session = typeof session.$inferSelect;
Expand Down
136 changes: 79 additions & 57 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import { superForm } from "sveltekit-superforms";
import { schema } from "./schema";
import * as Form from "$lib/components/ui/form/index.js";
import { Separator } from "$lib/components/ui/separator";
import UserCog from "lucide-svelte/icons/user-cog";
import { route } from "$lib/ROUTES";
import { i18n } from "$lib/i18n";
let { data }: { data: PageServerData } = $props();
const form = superForm(data.form, {
Expand All @@ -19,67 +22,86 @@
<main class="my-8 flex flex-1 flex-col items-center gap-4 p-4">
<h1 class="font-mono text-lg">Welcome {data.user.email}!</h1>

<div class="w-full max-w-xs">
<h2 class="font-mono text-lg">{m.bold_proof_grizzly_rush()}</h2>
<div class="flex w-full max-w-2xl flex-col items-center gap-4 md:flex-row md:items-stretch">
<div class="w-full max-w-xs">
<h2 class="font-mono text-lg">{m.bold_proof_grizzly_rush()}</h2>

<form method="post" use:enhance class="flex w-full max-w-xs flex-col gap-4">
<Form.Field {form} name="email">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.dark_weak_vulture_bless()}</Form.Label>
<Input {...props} type="email" readonly bind:value={$formData.email} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>

<form method="post" use:enhance class="flex w-full max-w-xs flex-col gap-4">
<Form.Field {form} name="email">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.dark_weak_vulture_bless()}</Form.Label>
<Input {...props} type="email" readonly bind:value={$formData.email} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field {form} name="firstNames">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.giant_jolly_mayfly_lead()}</Form.Label>
<Input {...props} bind:value={$formData.firstNames} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>

<Form.Field {form} name="firstNames">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.giant_jolly_mayfly_lead()}</Form.Label>
<Input {...props} bind:value={$formData.firstNames} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field {form} name="lastName">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.frail_fine_fish_chop()}</Form.Label>
<Input {...props} bind:value={$formData.lastName} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>

<Form.Field {form} name="lastName">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.frail_fine_fish_chop()}</Form.Label>
<Input {...props} bind:value={$formData.lastName} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field {form} name="homeMunicipality">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.lofty_patient_squid_drop()}</Form.Label>
<Input {...props} bind:value={$formData.homeMunicipality} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>

<Form.Field {form} name="homeMunicipality">
<Form.Control>
{#snippet children({ props })}
<Form.Label>{m.lofty_patient_squid_drop()}</Form.Label>
<Input {...props} bind:value={$formData.homeMunicipality} />
{/snippet}
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field
{form}
name="isAllowedEmails"
class="space-y flex flex-row items-center justify-between rounded-lg border p-4"
>
<Form.Control>
{#snippet children({ props })}
<div class="space-y-0.5">
<Form.Label>{m.light_frail_poodle_enrich()}</Form.Label>
<Form.Description>{m.livid_trite_thrush_animate()}</Form.Description>
</div>
<Switch {...props} bind:checked={$formData.isAllowedEmails} />
{/snippet}
</Form.Control>
</Form.Field>

<Form.Field
{form}
name="isAllowedEmails"
class="space-y flex flex-row items-center justify-between rounded-lg border p-4"
>
<Form.Control>
{#snippet children({ props })}
<div class="space-y-0.5">
<Form.Label>{m.light_frail_poodle_enrich()}</Form.Label>
<Form.Description>{m.livid_trite_thrush_animate()}</Form.Description>
</div>
<Switch {...props} bind:checked={$formData.isAllowedEmails} />
{/snippet}
</Form.Control>
</Form.Field>
<Form.Button type="submit">{m.tough_mellow_porpoise_explore()}</Form.Button>
</form>
</div>

<Form.Button type="submit">{m.tough_mellow_porpoise_explore()}</Form.Button>
</form>
{#if data.user.isAdmin}
<Separator class="hidden md:block" orientation="vertical" />
<div class="w-full max-w-xs">
<h2 class="font-mono text-lg">{m.each_strong_butterfly_seek()}</h2>
<a
href={route("/admin/memberships")}
class="flex items-center space-x-4 rounded-md border p-4 hover:bg-card-foreground/10"
>
<UserCog class="h-6 w-6" />
<div class="flex-1 space-y-1">
<p class="text-sm font-medium leading-none">Manage memberships</p>
<p class="text-sm text-muted-foreground">Configure price and period</p>
</div>
</a>
</div>
{/if}
</div>
</main>
1 change: 1 addition & 0 deletions src/routes/admin/memberships/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asd

0 comments on commit 82c4872

Please sign in to comment.