Skip to content
TypeScript

feat: add domain types, date helpers and seed data

Vipul Kumar760cef6aff9c
diff --git a/src/lib/dates.ts b/src/lib/dates.ts
new file mode 100644
index 0000000..c4a261b
--- /dev/null
+++ b/src/lib/dates.ts
@@ -0,0 +1,176 @@
+// Pure date helpers. Days are "YYYY-MM-DD" keys in local time so nothing
+// drifts across time zones or between server and client renders.
+
+export const MONTHS = [
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December",
+];
+export const MONTHS_SHORT = MONTHS.map((m) => m.slice(0, 3));
+export const WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
+export const WEEKDAYS_SHORT = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
+
+const pad = (n: number) => String(n).padStart(2, "0");
+
+export function toKey(d: Date): string {
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
+}
+
+export function fromKey(key: string): Date {
+ const [y, m, d] = key.split("-").map(Number);
+ return new Date(y, m - 1, d);
+}
+
+export function addDays(key: string, n: number): string {
+ const d = fromKey(key);
+ d.setDate(d.getDate() + n);
+ return toKey(d);
+}
+
+export function addMonths(key: string, n: number): string {
+ const d = fromKey(key);
+ const day = d.getDate();
+ d.setDate(1);
+ d.setMonth(d.getMonth() + n);
+ const last = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
+ d.setDate(Math.min(day, last));
+ return toKey(d);
+}
+
+export function dayOfWeek(key: string): number {
+ return fromKey(key).getDay();
+}
+
+export function startOfWeek(key: string, weekStartsOn: 0 | 1 = 0): string {
+ const dow = dayOfWeek(key);
+ const diff = (dow - weekStartsOn + 7) % 7;
+ return addDays(key, -diff);
+}
+
+export function weekDays(key: string, weekStartsOn: 0 | 1 = 0): string[] {
+ const start = startOfWeek(key, weekStartsOn);
+ return Array.from({ length: 7 }, (_, i) => addDays(start, i));
+}
+
+export function startOfMonth(key: string): string {
+ return key.slice(0, 8) + "01";
+}
+
+export function daysInMonth(key: string): number {
+ const d = fromKey(key);
+ return new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
+}
+
+/** 6×7 grid of days covering the month of `key`. */
+export function monthGrid(key: string, weekStartsOn: 0 | 1 = 0): string[] {
+ const first = startOfWeek(startOfMonth(key), weekStartsOn);
+ return Array.from({ length: 42 }, (_, i) => addDays(first, i));
+}
+
+/** ISO-8601 week number of the given day. */
+export function isoWeek(key: string): number {
+ const d = fromKey(key);
+ const target = new Date(d.getFullYear(), d.getMonth(), d.getDate());
+ const dayNr = (target.getDay() + 6) % 7;
+ target.setDate(target.getDate() - dayNr + 3);
+ const firstThursday = new Date(target.getFullYear(), 0, 4);
+ const diff = (target.getTime() - firstThursday.getTime()) / 86400000;
+ return 1 + Math.round((diff - 3 + ((firstThursday.getDay() + 6) % 7)) / 7);
+}
+
+export function diffDays(a: string, b: string): number {
+ return Math.round((fromKey(b).getTime() - fromKey(a).getTime()) / 86400000);
+}
+
+export function rangeKeys(from: string, to: string): string[] {
+ const n = diffDays(from, to);
+ if (n < 0) return [];
+ return Array.from({ length: n + 1 }, (_, i) => addDays(from, i));
+}
+
+export function isWeekend(key: string): boolean {
+ const d = dayOfWeek(key);
+ return d === 0 || d === 6;
+}
+
+export function monthName(key: string): string {
+ return MONTHS[fromKey(key).getMonth()];
+}
+
+export function formatLong(key: string): string {
+ const d = fromKey(key);
+ return `${MONTHS[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
+}
+
+export function formatShort(key: string): string {
+ const d = fromKey(key);
+ return `${MONTHS_SHORT[d.getMonth()]} ${d.getDate()}`;
+}
+
+export function formatWeekday(key: string): string {
+ return WEEKDAYS[dayOfWeek(key)];
+}
+
+export function formatRange(from: string, to: string): string {
+ const a = fromKey(from);
+ const b = fromKey(to);
+ if (a.getMonth() === b.getMonth() && a.getFullYear() === b.getFullYear()) {
+ return `${MONTHS_SHORT[a.getMonth()]} ${a.getDate()} – ${b.getDate()}`;
+ }
+ return `${formatShort(from)} – ${formatShort(to)}`;
+}
+
+export function formatTime(minutes: number, format: "24h" | "12h" = "24h"): string {
+ const m = ((minutes % 1440) + 1440) % 1440;
+ const h = Math.floor(m / 60);
+ const mm = m % 60;
+ if (minutes === 1440) return format === "24h" ? "24:00" : "12:00 AM";
+ if (format === "24h") return `${pad(h)}:${pad(mm)}`;
+ const suffix = h < 12 ? "AM" : "PM";
+ const h12 = h % 12 === 0 ? 12 : h % 12;
+ return `${h12}:${pad(mm)} ${suffix}`;
+}
+
+export function formatTimeRange(start: number, end: number, format: "24h" | "12h" = "24h") {
+ return `${formatTime(start, format)} – ${formatTime(end, format)}`;
+}
+
+export function parseTime(value: string): number {
+ const [h, m] = value.split(":").map(Number);
+ return (h || 0) * 60 + (m || 0);
+}
+
+export function timeInputValue(minutes: number): string {
+ const m = Math.min(minutes, 1439);
+ return `${pad(Math.floor(m / 60))}:${pad(m % 60)}`;
+}
+
+export function formatDuration(minutes: number): string {
+ const h = Math.floor(minutes / 60);
+ const m = minutes % 60;
+ if (h && m) return `${h}h ${m}m`;
+ if (h) return `${h}h`;
+ return `${m}m`;
+}
+
+export function relativeTime(iso: string, now: number): string {
+ const diff = Math.max(0, now - new Date(iso).getTime());
+ const min = Math.floor(diff / 60000);
+ if (min < 1) return "Just now";
+ if (min < 60) return `${min}m ago`;
+ const h = Math.floor(min / 60);
+ if (h < 24) return `${h}h ago`;
+ const d = Math.floor(h / 24);
+ if (d < 7) return `${d}d ago`;
+ const date = new Date(iso);
+ return `${MONTHS_SHORT[date.getMonth()]} ${date.getDate()}`;
+}
diff --git a/src/lib/leave.ts b/src/lib/leave.ts
new file mode 100644
index 0000000..f354e2a
--- /dev/null
+++ b/src/lib/leave.ts
@@ -0,0 +1,71 @@
+import { isWeekend, rangeKeys } from "./dates";
+import type { AppState, EventColor, Holiday, LeaveType } from "./types";
+
+export const LEAVE_TYPES: LeaveType[] = ["Time off", "Sick", "Extra leave", "Half-day leave", "Personal"];
+
+export const LEAVE_COLORS: Record<LeaveType, EventColor> = {
+ "Time off": "green",
+ Sick: "blue",
+ "Extra leave": "pink",
+ "Half-day leave": "green",
+ Personal: "orange",
+};
+
+export const WORKDAY_MINUTES = 8 * 60;
+
+/** Working days between two dates, skipping weekends and public holidays. */
+export function workingDays(from: string, to: string, holidays: Holiday[]): string[] {
+ const off = new Set(holidays.map((h) => h.date));
+ return rangeKeys(from, to).filter((d) => !isWeekend(d) && !off.has(d));
+}
+
+export function durationLabel(days: number, hours: number): string {
+ const parts: string[] = [];
+ if (days) parts.push(`${days} ${days === 1 ? "day" : "days"}`);
+ if (hours) parts.push(`${hours} ${hours === 1 ? "hour" : "hours"}`);
+ return parts.join(" ") || "0 hours";
+}
+
+export function formatDays(n: number): string {
+ const rounded = Math.round(n * 100) / 100;
+ return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(2).replace(/0+$/, "").replace(/\.$/, "");
+}
+
+export function plural(n: number, one: string, many: string) {
+ return `${formatDays(n)} ${n === 1 ? one : many}`;
+}
+
+export type LeaveStats = {
+ available: number;
+ pendingCount: number;
+ pendingDays: number;
+ upcoming: number;
+ taken: number;
+ contract: number;
+ carryover: number;
+ holidays: number;
+};
+
+export function computeLeaveStats(
+ s: Pick<AppState, "requests" | "settings" | "holidays">,
+ today: string,
+): LeaveStats {
+ const year = today.slice(0, 4);
+ const thisYear = s.requests.filter((r) => r.from.slice(0, 4) === year);
+ const approved = thisYear.filter((r) => r.status === "approved");
+ const pending = thisYear.filter((r) => r.status === "pending");
+ const used = approved.reduce((a, r) => a + r.days, 0);
+ const pendingDays = pending.reduce((a, r) => a + r.days, 0);
+ const upcoming = approved.filter((r) => r.from >= today).reduce((a, r) => a + r.days, 0);
+ const total = s.settings.contractDays + s.settings.carryoverDays;
+ return {
+ available: Math.max(0, total - used - pendingDays),
+ pendingCount: pending.length,
+ pendingDays,
+ upcoming,
+ taken: used - upcoming,
+ contract: s.settings.contractDays,
+ carryover: s.settings.carryoverDays,
+ holidays: s.holidays.filter((h) => h.date.slice(0, 4) === year).length,
+ };
+}
diff --git a/src/lib/seed.ts b/src/lib/seed.ts
new file mode 100644
index 0000000..fedddc2
--- /dev/null
+++ b/src/lib/seed.ts
@@ -0,0 +1,386 @@
+import type { AppState } from "./types";
+
+/** The calendar opens on the week shown in the design, with Tue Nov 10 selected. */
+export const DESIGN_DATE = "2026-11-10";
+
+/** Used only for server rendering; the browser swaps in the real date on hydration. */
+export const SERVER_TODAY = "2026-10-26";
+
+export const STATE_VERSION = 1;
+
+const h = (hours: number, minutes = 0) => hours * 60 + minutes;
+
+export function createSeed(): AppState {
+ return {
+ version: STATE_VERSION,
+ workspaceId: "ws-main",
+ workspaces: [
+ { id: "ws-main", name: "Workspace" },
+ { id: "ws-acme", name: "Acme Studio" },
+ { id: "ws-personal", name: "Personal" },
+ ],
+ events: [
+ { id: "ev-1", title: "Time off", date: "2026-11-09", start: 0, end: 1440, allDay: true, color: "green", requestId: "rq-5" },
+ { id: "ev-2", title: "Personal matters", date: "2026-11-08", start: h(11), end: h(12), allDay: false, color: "cyan" },
+ {
+ id: "ev-3",
+ title: "Personal appointment",
+ date: "2026-11-10",
+ start: h(7),
+ end: h(9),
+ allDay: false,
+ color: "orange",
+ note: "Pending",
+ requestId: "rq-6",
+ },
+ {
+ id: "ev-4",
+ title: "Extra leave",
+ date: "2026-11-10",
+ start: h(11),
+ end: h(13),
+ allDay: false,
+ color: "pink",
+ note: "From carryover days",
+ },
+ { id: "ev-5", title: "Submit medical certificate", date: "2026-11-11", start: h(10), end: h(11), allDay: false, color: "blue" },
+ { id: "ev-6", title: "Update time tracking", date: "2026-11-12", start: h(7, 30), end: h(8), allDay: false, color: "cyan" },
+ { id: "ev-7", title: "Benefits review", date: "2026-11-12", start: h(12), end: h(13), allDay: false, color: "blue" },
+ {
+ id: "ev-8",
+ title: "Half-day leave",
+ date: "2026-11-13",
+ start: h(8),
+ end: h(12),
+ allDay: false,
+ color: "green",
+ note: "Approved",
+ requestId: "rq-7",
+ },
+ { id: "ev-9", title: "Team sync", date: "2026-10-26", start: h(9, 30), end: h(10), allDay: false, color: "blue" },
+ { id: "ev-10", title: "Design review", date: "2026-10-27", start: h(14), end: h(15, 30), allDay: false, color: "purple" },
+ { id: "ev-11", title: "Payroll cut-off", date: "2026-10-30", start: 0, end: 1440, allDay: true, color: "orange" },
+ { id: "ev-12", title: "1:1 with manager", date: "2026-11-04", start: h(11), end: h(11, 30), allDay: false, color: "cyan" },
+ { id: "ev-13", title: "Time off", date: "2026-12-23", start: 0, end: 1440, allDay: true, color: "green", requestId: "rq-8" },
+ { id: "ev-14", title: "Time off", date: "2026-12-24", start: h(8), end: h(12), allDay: false, color: "green", note: "Approved", requestId: "rq-8" },
+ { id: "ev-15", title: "Time off", date: "2026-12-28", start: h(9), end: h(15), allDay: false, color: "green", note: "Pending", requestId: "rq-9" },
+ ],
+ requests: [
+ {
+ id: "rq-1",
+ status: "approved",
+ type: "Time off",
+ duration: "2 days 4 hours",
+ days: 2.5,
+ from: "2026-04-19",
+ to: "2026-04-22",
+ allDay: true,
+ notes: "Family vacation, including a half-day leave on April 19",
+ submittedAt: "2026-04-02T09:12:00.000Z",
+ },
+ {
+ id: "rq-2",
+ status: "declined",
+ type: "Sick",
+ duration: "1 days, 2 hour",
+ days: 1.25,
+ from: "2026-04-17",
+ to: "2026-04-19",
+ allDay: true,
+ notes: "Request submitted without medical certificate",
+ submittedAt: "2026-03-30T08:40:00.000Z",
+ },
+ {
+ id: "rq-3",
+ status: "approved",
+ type: "Time off",
+ duration: "2 days, 7 hour",
+ days: 1.5,
+ from: "2026-04-12",
+ to: "2026-04-16",
+ allDay: true,
+ notes: "Traveling out of town for personal matters",
+ submittedAt: "2026-03-24T15:05:00.000Z",
+ },
+ {
+ id: "rq-4",
+ status: "approved",
+ type: "Time off",
+ duration: "1 days, 10 hour",
+ days: 1,
+ from: "2026-04-08",
+ to: "2026-04-14",
+ allDay: true,
+ notes: "Personal appointment during working hours",
+ submittedAt: "2026-03-18T11:30:00.000Z",
+ },
+ {
+ id: "rq-5",
+ status: "approved",
+ type: "Time off",
+ duration: "1 day",
+ days: 1,
+ from: "2026-11-09",
+ to: "2026-11-09",
+ allDay: true,
+ notes: "Long weekend",
+ submittedAt: "2026-03-10T10:00:00.000Z",
+ },
+ {
+ id: "rq-6",
+ status: "pending",
+ type: "Personal",
+ duration: "2 hours",
+ days: 0.25,
+ from: "2026-11-10",
+ to: "2026-11-10",
+ allDay: false,
+ start: h(7),
+ end: h(9),
+ notes: "Personal appointment",
+ submittedAt: "2026-03-08T10:00:00.000Z",
+ },
+ {
+ id: "rq-7",
+ status: "approved",
+ type: "Half-day leave",
+ duration: "4 hours",
+ days: 0.5,
+ from: "2026-11-13",
+ to: "2026-11-13",
+ allDay: false,
+ start: h(8),
+ end: h(12),
+ notes: "Half-day leave",
+ submittedAt: "2026-03-05T10:00:00.000Z",
+ },
+ {
+ id: "rq-8",
+ status: "approved",
+ type: "Time off",
+ duration: "1 day 4 hours",
+ days: 1.5,
+ from: "2026-12-23",
+ to: "2026-12-24",
+ allDay: true,
+ notes: "Holiday travel",
+ submittedAt: "2026-02-20T10:00:00.000Z",
+ },
+ {
+ id: "rq-9",
+ status: "pending",
+ type: "Time off",
+ duration: "6 hours",
+ days: 0.75,
+ from: "2026-12-28",
+ to: "2026-12-28",
+ allDay: false,
+ start: h(9),
+ end: h(15),
+ notes: "Moving apartments",
+ submittedAt: "2026-02-12T10:00:00.000Z",
+ },
+ ],
+ holidays: [
+ { id: "ho-1", date: "2026-01-01", name: "New Year's Day" },
+ { id: "ho-2", date: "2026-01-26", name: "Republic Day" },
+ { id: "ho-3", date: "2026-03-04", name: "Holi" },
+ { id: "ho-4", date: "2026-04-03", name: "Good Friday" },
+ { id: "ho-5", date: "2026-05-01", name: "Labour Day" },
+ { id: "ho-6", date: "2026-06-26", name: "Muharram" },
+ { id: "ho-7", date: "2026-08-15", name: "Independence Day" },
+ { id: "ho-8", date: "2026-10-02", name: "Gandhi Jayanti" },
+ { id: "ho-9", date: "2026-10-20", name: "Dussehra" },
+ { id: "ho-10", date: "2026-11-14", name: "Diwali" },
+ { id: "ho-11", date: "2026-11-24", name: "Guru Nanak Jayanti" },
+ { id: "ho-12", date: "2026-12-25", name: "Christmas Day" },
+ ],
+ profile: {
+ name: "Harry Potter",
+ email: "[email protected]",
+ initials: "EX",
+ phone: "+44 20 7946 0958",
+ jobTitle: "Product Designer",
+ department: "Design",
+ manager: "Minerva McGonagall",
+ location: "London, UK",
+ startDate: "2023-09-01",
+ birthday: "1980-07-31",
+ address: "4 Privet Drive, Little Whinging, Surrey",
+ emergencyContact: "Ron Weasley · +44 20 7946 0101",
+ bio: "Designs calm, fast interfaces for the people team.",
+ },
+ settings: {
+ weekStartsOn: 0,
+ timeFormat: "24h",
+ dayStartHour: 6,
+ contractDays: 12,
+ carryoverDays: 4,
+ showWeekends: true,
+ emailNotifications: true,
+ pushNotifications: false,
+ weeklyDigest: true,
+ },
+ notifications: [
+ {
+ id: "no-1",
+ title: "Half-day leave approved",
+ body: "Your half-day leave on Nov 13 was approved by Minerva.",
+ createdAt: "2026-10-25T16:20:00.000Z",
+ read: true,
+ href: "/time-off",
+ },
+ {
+ id: "no-2",
+ title: "Medical certificate due",
+ body: "Upload your certificate before Nov 11 to keep your sick leave valid.",
+ createdAt: "2026-10-24T09:00:00.000Z",
+ read: true,
+ href: "/documents",
+ },
+ {
+ id: "no-3",
+ title: "Benefits review scheduled",
+ body: "A benefits review was added to your calendar for Nov 12.",
+ createdAt: "2026-10-21T13:45:00.000Z",
+ read: true,
+ href: "/benefits",
+ },
+ ],
+ documents: [
+ { id: "doc-1", name: "Employment contract.pdf", category: "Contract", size: 482_311, uploadedAt: "2023-08-21T10:00:00.000Z", starred: true },
+ { id: "doc-2", name: "Payslip – September 2026.pdf", category: "Payslip", size: 121_004, uploadedAt: "2026-09-30T10:00:00.000Z" },
+ { id: "doc-3", name: "Payslip – August 2026.pdf", category: "Payslip", size: 119_662, uploadedAt: "2026-08-31T10:00:00.000Z" },
+ { id: "doc-4", name: "Leave policy 2026.pdf", category: "Policy", size: 248_120, uploadedAt: "2026-01-04T10:00:00.000Z" },
+ { id: "doc-5", name: "P60 – 2025.pdf", category: "Tax", size: 88_430, uploadedAt: "2026-05-12T10:00:00.000Z" },
+ { id: "doc-6", name: "Remote work agreement.pdf", category: "Contract", size: 201_877, uploadedAt: "2025-02-17T10:00:00.000Z" },
+ ],
+ timeEntries: [
+ { id: "te-1", date: "2026-10-26", project: "Calendar app", task: "Week view polish", minutes: 150, billable: true },
+ { id: "te-2", date: "2026-10-23", project: "Calendar app", task: "Event drag & drop", minutes: 240, billable: true },
+ { id: "te-3", date: "2026-10-23", project: "Internal", task: "Team sync", minutes: 30, billable: false },
+ { id: "te-4", date: "2026-10-22", project: "Design system", task: "Token audit", minutes: 300, billable: true },
+ { id: "te-5", date: "2026-10-21", project: "Calendar app", task: "Request flow", minutes: 360, billable: true },
+ { id: "te-6", date: "2026-10-20", project: "Internal", task: "Planning", minutes: 90, billable: false },
+ { id: "te-7", date: "2026-10-20", project: "Design system", task: "Icon review", minutes: 210, billable: true },
+ ],
+ timer: { running: false, startedAt: null, project: "Calendar app", task: "" },
+ invoices: [
+ {
+ id: "in-1",
+ number: "INV-2026-014",
+ client: "Acme Studio",
+ issueDate: "2026-10-01",
+ dueDate: "2026-10-31",
+ status: "sent",
+ currency: "USD",
+ notes: "Thank you for your business.",
+ items: [
+ { id: "it-1", description: "Product design — October", quantity: 80, rate: 65 },
+ { id: "it-2", description: "Design system maintenance", quantity: 12, rate: 65 },
+ ],
+ },
+ {
+ id: "in-2",
+ number: "INV-2026-013",
+ client: "Acme Studio",
+ issueDate: "2026-09-01",
+ dueDate: "2026-09-30",
+ status: "paid",
+ currency: "USD",
+ notes: "",
+ items: [{ id: "it-3", description: "Product design — September", quantity: 76, rate: 65 }],
+ },
+ {
+ id: "in-3",
+ number: "INV-2026-012",
+ client: "Northwind Labs",
+ issueDate: "2026-08-14",
+ dueDate: "2026-09-13",
+ status: "overdue",
+ currency: "USD",
+ notes: "Second reminder sent.",
+ items: [{ id: "it-4", description: "UX audit", quantity: 1, rate: 2400 }],
+ },
+ ],
+ withdrawalMethods: [
+ {
+ id: "wm-1",
+ kind: "bank",
+ label: "Barclays Current",
+ holder: "Harry Potter",
+ last4: "4821",
+ currency: "GBP",
+ isDefault: true,
+ addedAt: "2024-01-12T10:00:00.000Z",
+ },
+ {
+ id: "wm-2",
+ kind: "paypal",
+ label: "PayPal",
+ holder: "[email protected]",
+ last4: "",
+ currency: "USD",
+ isDefault: false,
+ addedAt: "2025-06-02T10:00:00.000Z",
+ },
+ ],
+ benefits: [
+ {
+ id: "be-1",
+ name: "Private health insurance",
+ provider: "Bupa",
+ category: "Health",
+ description: "Comprehensive cover including outpatient, dental and optical.",
+ budget: 0,
+ used: 0,
+ enrolled: true,
+ renewsOn: "2027-01-01",
+ },
+ {
+ id: "be-2",
+ name: "Learning budget",
+ provider: "Company",
+ category: "Learning",
+ description: "Courses, books and conferences that help you grow.",
+ budget: 1500,
+ used: 420,
+ enrolled: true,
+ renewsOn: "2027-01-01",
+ },
+ {
+ id: "be-3",
+ name: "Wellness allowance",
+ provider: "ClassPass",
+ category: "Wellness",
+ description: "Gym, yoga and mental-health apps every month.",
+ budget: 600,
+ used: 275,
+ enrolled: true,
+ renewsOn: "2027-01-01",
+ },
+ {
+ id: "be-4",
+ name: "Pension matching",
+ provider: "Aviva",
+ category: "Financial",
+ description: "We match contributions up to 5% of your salary.",
+ budget: 0,
+ used: 0,
+ enrolled: false,
+ renewsOn: "2027-04-06",
+ },
+ {
+ id: "be-5",
+ name: "Home office stipend",
+ provider: "Company",
+ category: "Lifestyle",
+ description: "Desk, chair, monitor — whatever makes home work better.",
+ budget: 800,
+ used: 0,
+ enrolled: false,
+ renewsOn: "2027-01-01",
+ },
+ ],
+ };
+}
diff --git a/src/lib/types.ts b/src/lib/types.ts
new file mode 100644
index 0000000..0fea6d7
--- /dev/null
+++ b/src/lib/types.ts
@@ -0,0 +1,161 @@
+export type EventColor = "green" | "purple" | "cyan" | "orange" | "pink" | "blue";
+
+/** Dates are local calendar days stored as "YYYY-MM-DD"; times are minutes from midnight. */
+export type CalEvent = {
+ id: string;
+ title: string;
+ date: string;
+ start: number;
+ end: number;
+ allDay: boolean;
+ color: EventColor;
+ note?: string;
+ location?: string;
+ requestId?: string;
+};
+
+export type LeaveStatus = "approved" | "pending" | "declined" | "cancelled";
+
+export type LeaveType = "Time off" | "Sick" | "Extra leave" | "Half-day leave" | "Personal";
+
+export type LeaveRequest = {
+ id: string;
+ status: LeaveStatus;
+ type: LeaveType;
+ /** Human label shown in the table, e.g. "2 days 4 hours" */
+ duration: string;
+ /** Days counted against the allowance */
+ days: number;
+ from: string;
+ to: string;
+ allDay: boolean;
+ start?: number;
+ end?: number;
+ notes: string;
+ submittedAt: string;
+};
+
+export type Holiday = { id: string; date: string; name: string };
+
+export type Profile = {
+ name: string;
+ email: string;
+ initials: string;
+ phone: string;
+ jobTitle: string;
+ department: string;
+ manager: string;
+ location: string;
+ startDate: string;
+ birthday: string;
+ address: string;
+ emergencyContact: string;
+ bio: string;
+};
+
+export type Settings = {
+ weekStartsOn: 0 | 1;
+ timeFormat: "24h" | "12h";
+ dayStartHour: number;
+ contractDays: number;
+ carryoverDays: number;
+ showWeekends: boolean;
+ emailNotifications: boolean;
+ pushNotifications: boolean;
+ weeklyDigest: boolean;
+};
+
+export type AppNotification = {
+ id: string;
+ title: string;
+ body: string;
+ createdAt: string;
+ read: boolean;
+ href?: string;
+};
+
+export type DocCategory = "Contract" | "Payslip" | "Policy" | "Medical" | "Tax" | "Other";
+
+export type DocumentFile = {
+ id: string;
+ name: string;
+ category: DocCategory;
+ size: number;
+ uploadedAt: string;
+ /** data: URL for files uploaded in this browser (small files only) */
+ dataUrl?: string;
+ starred?: boolean;
+};
+
+export type TimeEntry = {
+ id: string;
+ date: string;
+ project: string;
+ task: string;
+ minutes: number;
+ billable: boolean;
+};
+
+export type Timer = { running: boolean; startedAt: number | null; project: string; task: string };
+
+export type InvoiceStatus = "draft" | "sent" | "paid" | "overdue";
+
+export type InvoiceItem = { id: string; description: string; quantity: number; rate: number };
+
+export type Invoice = {
+ id: string;
+ number: string;
+ client: string;
+ issueDate: string;
+ dueDate: string;
+ status: InvoiceStatus;
+ items: InvoiceItem[];
+ notes: string;
+ currency: string;
+};
+
+export type WithdrawalKind = "bank" | "paypal" | "wise" | "card";
+
+export type WithdrawalMethod = {
+ id: string;
+ kind: WithdrawalKind;
+ label: string;
+ holder: string;
+ /** Masked tail only, never a full number */
+ last4: string;
+ currency: string;
+ isDefault: boolean;
+ addedAt: string;
+};
+
+export type Benefit = {
+ id: string;
+ name: string;
+ provider: string;
+ category: "Health" | "Wellness" | "Learning" | "Financial" | "Lifestyle";
+ description: string;
+ budget: number;
+ used: number;
+ enrolled: boolean;
+ renewsOn: string;
+};
+
+export type Workspace = { id: string; name: string };
+
+export type AppState = {
+ version: number;
+ workspaceId: string;
+ workspaces: Workspace[];
+ events: CalEvent[];
+ requests: LeaveRequest[];
+ holidays: Holiday[];
+ profile: Profile;
+ settings: Settings;
+ notifications: AppNotification[];
+ documents: DocumentFile[];
+ timeEntries: TimeEntry[];
+ timer: Timer;
+ invoices: Invoice[];
+ withdrawalMethods: WithdrawalMethod[];
+ benefits: Benefit[];
+};