17 Commits
2.2.1 ... 2.4.0

Author SHA1 Message Date
caf763aa1e Moar
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m6s
2026-02-09 02:28:54 -07:00
12d59bb42f Refactored a bunch of shit
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m57s
2026-02-09 01:49:19 -07:00
c39865031a Deps
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m3s
2026-02-02 23:19:50 -07:00
abbf39f160 Theme select & Accessability :^)
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m0s
2026-01-27 14:26:14 -07:00
e2949a28ef Update new.astro
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m9s
2026-01-20 12:59:32 -07:00
8b91ec7a71 Updated to Astro 6 beta
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m52s
2026-01-20 12:37:08 -07:00
815c08dd50 Schema fixes
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m59s
2026-01-20 12:08:06 -07:00
55eb03165e Fixed migrations
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m2s
2026-01-20 11:36:52 -07:00
a4071d6e40 Fixed charts
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m3s
2026-01-20 11:24:41 -07:00
fff0e14a4b Fixed
Some checks failed
Docker Deploy / build-and-push (push) Failing after 3m7s
2026-01-20 11:10:31 -07:00
ad7dc18780 Switch to tags
Some checks failed
Docker Deploy / build-and-push (push) Has been cancelled
2026-01-20 11:09:09 -07:00
de5b1063b7 Migrate
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m24s
2026-01-20 10:47:43 -07:00
82b45fdfe4 O_O
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m2s
2026-01-20 10:32:14 -07:00
b5ac2e0608 Oops
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m0s
2026-01-20 01:21:56 -07:00
6bed4b4709 Last fix for the night...
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m9s
2026-01-20 01:06:06 -07:00
54cac49b70 OOOOOPS
All checks were successful
Docker Deploy / build-and-push (push) Successful in 3m56s
2026-01-19 23:39:00 -07:00
effc6ac37e oops
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m6s
2026-01-19 22:25:25 -07:00
87 changed files with 4376 additions and 7120 deletions

View File

@@ -10,11 +10,12 @@ import node from "@astrojs/node";
export default defineConfig({ export default defineConfig({
output: "server", output: "server",
integrations: [vue(), icon()], integrations: [vue(), icon()],
security: {
csp: process.env.NODE_ENV === "production",
},
vite: { vite: {
plugins: [tailwindcss()], plugins: [tailwindcss()],
}, },
adapter: node({ adapter: node({
mode: "standalone", mode: "standalone",
}), }),

View File

@@ -10,24 +10,23 @@ CREATE TABLE `api_tokens` (
); );
--> statement-breakpoint --> statement-breakpoint
CREATE UNIQUE INDEX `api_tokens_token_unique` ON `api_tokens` (`token`);--> statement-breakpoint CREATE UNIQUE INDEX `api_tokens_token_unique` ON `api_tokens` (`token`);--> statement-breakpoint
CREATE TABLE `categories` ( CREATE INDEX `api_tokens_user_id_idx` ON `api_tokens` (`user_id`);--> statement-breakpoint
`id` text PRIMARY KEY NOT NULL,
`organization_id` text NOT NULL,
`name` text NOT NULL,
`color` text,
`created_at` integer,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `clients` ( CREATE TABLE `clients` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`organization_id` text NOT NULL, `organization_id` text NOT NULL,
`name` text NOT NULL, `name` text NOT NULL,
`email` text, `email` text,
`phone` text,
`street` text,
`city` text,
`state` text,
`zip` text,
`country` text,
`created_at` integer, `created_at` integer,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `clients_organization_id_idx` ON `clients` (`organization_id`);--> statement-breakpoint
CREATE TABLE `invoice_items` ( CREATE TABLE `invoice_items` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`invoice_id` text NOT NULL, `invoice_id` text NOT NULL,
@@ -38,6 +37,7 @@ CREATE TABLE `invoice_items` (
FOREIGN KEY (`invoice_id`) REFERENCES `invoices`(`id`) ON UPDATE no action ON DELETE no action FOREIGN KEY (`invoice_id`) REFERENCES `invoices`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `invoice_items_invoice_id_idx` ON `invoice_items` (`invoice_id`);--> statement-breakpoint
CREATE TABLE `invoices` ( CREATE TABLE `invoices` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`organization_id` text NOT NULL, `organization_id` text NOT NULL,
@@ -50,6 +50,9 @@ CREATE TABLE `invoices` (
`notes` text, `notes` text,
`currency` text DEFAULT 'USD' NOT NULL, `currency` text DEFAULT 'USD' NOT NULL,
`subtotal` integer DEFAULT 0 NOT NULL, `subtotal` integer DEFAULT 0 NOT NULL,
`discount_value` real DEFAULT 0,
`discount_type` text DEFAULT 'percentage',
`discount_amount` integer DEFAULT 0,
`tax_rate` real DEFAULT 0, `tax_rate` real DEFAULT 0,
`tax_amount` integer DEFAULT 0 NOT NULL, `tax_amount` integer DEFAULT 0 NOT NULL,
`total` integer DEFAULT 0 NOT NULL, `total` integer DEFAULT 0 NOT NULL,
@@ -58,6 +61,8 @@ CREATE TABLE `invoices` (
FOREIGN KEY (`client_id`) REFERENCES `clients`(`id`) ON UPDATE no action ON DELETE no action FOREIGN KEY (`client_id`) REFERENCES `clients`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `invoices_organization_id_idx` ON `invoices` (`organization_id`);--> statement-breakpoint
CREATE INDEX `invoices_client_id_idx` ON `invoices` (`client_id`);--> statement-breakpoint
CREATE TABLE `members` ( CREATE TABLE `members` (
`user_id` text NOT NULL, `user_id` text NOT NULL,
`organization_id` text NOT NULL, `organization_id` text NOT NULL,
@@ -68,6 +73,8 @@ CREATE TABLE `members` (
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `members_user_id_idx` ON `members` (`user_id`);--> statement-breakpoint
CREATE INDEX `members_organization_id_idx` ON `members` (`organization_id`);--> statement-breakpoint
CREATE TABLE `organizations` ( CREATE TABLE `organizations` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL, `name` text NOT NULL,
@@ -77,9 +84,33 @@ CREATE TABLE `organizations` (
`state` text, `state` text,
`zip` text, `zip` text,
`country` text, `country` text,
`default_tax_rate` real DEFAULT 0,
`default_currency` text DEFAULT 'USD',
`created_at` integer `created_at` integer
); );
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE `passkey_challenges` (
`id` text PRIMARY KEY NOT NULL,
`challenge` text NOT NULL,
`user_id` text,
`expires_at` integer NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `passkey_challenges_challenge_unique` ON `passkey_challenges` (`challenge`);--> statement-breakpoint
CREATE TABLE `passkeys` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`public_key` text NOT NULL,
`counter` integer NOT NULL,
`device_type` text NOT NULL,
`backed_up` integer NOT NULL,
`transports` text,
`last_used_at` integer,
`created_at` integer,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE INDEX `passkeys_user_id_idx` ON `passkeys` (`user_id`);--> statement-breakpoint
CREATE TABLE `sessions` ( CREATE TABLE `sessions` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL, `user_id` text NOT NULL,
@@ -87,6 +118,7 @@ CREATE TABLE `sessions` (
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `sessions_user_id_idx` ON `sessions` (`user_id`);--> statement-breakpoint
CREATE TABLE `site_settings` ( CREATE TABLE `site_settings` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`key` text NOT NULL, `key` text NOT NULL,
@@ -100,27 +132,33 @@ CREATE TABLE `tags` (
`organization_id` text NOT NULL, `organization_id` text NOT NULL,
`name` text NOT NULL, `name` text NOT NULL,
`color` text, `color` text,
`rate` integer DEFAULT 0,
`created_at` integer, `created_at` integer,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `tags_organization_id_idx` ON `tags` (`organization_id`);--> statement-breakpoint
CREATE TABLE `time_entries` ( CREATE TABLE `time_entries` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL, `user_id` text NOT NULL,
`organization_id` text NOT NULL, `organization_id` text NOT NULL,
`client_id` text NOT NULL, `client_id` text NOT NULL,
`category_id` text NOT NULL,
`start_time` integer NOT NULL, `start_time` integer NOT NULL,
`end_time` integer, `end_time` integer,
`description` text, `description` text,
`invoice_id` text,
`is_manual` integer DEFAULT false, `is_manual` integer DEFAULT false,
`created_at` integer, `created_at` integer,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action, FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action, FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`client_id`) REFERENCES `clients`(`id`) ON UPDATE no action ON DELETE no action, FOREIGN KEY (`client_id`) REFERENCES `clients`(`id`) ON UPDATE no action ON DELETE no action
FOREIGN KEY (`category_id`) REFERENCES `categories`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `time_entries_user_id_idx` ON `time_entries` (`user_id`);--> statement-breakpoint
CREATE INDEX `time_entries_organization_id_idx` ON `time_entries` (`organization_id`);--> statement-breakpoint
CREATE INDEX `time_entries_client_id_idx` ON `time_entries` (`client_id`);--> statement-breakpoint
CREATE INDEX `time_entries_start_time_idx` ON `time_entries` (`start_time`);--> statement-breakpoint
CREATE INDEX `time_entries_invoice_id_idx` ON `time_entries` (`invoice_id`);--> statement-breakpoint
CREATE TABLE `time_entry_tags` ( CREATE TABLE `time_entry_tags` (
`time_entry_id` text NOT NULL, `time_entry_id` text NOT NULL,
`tag_id` text NOT NULL, `tag_id` text NOT NULL,
@@ -129,6 +167,8 @@ CREATE TABLE `time_entry_tags` (
FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE no action FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE no action
); );
--> statement-breakpoint --> statement-breakpoint
CREATE INDEX `time_entry_tags_time_entry_id_idx` ON `time_entry_tags` (`time_entry_id`);--> statement-breakpoint
CREATE INDEX `time_entry_tags_tag_id_idx` ON `time_entry_tags` (`tag_id`);--> statement-breakpoint
CREATE TABLE `users` ( CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL, `id` text PRIMARY KEY NOT NULL,
`email` text NOT NULL, `email` text NOT NULL,

View File

@@ -0,0 +1,3 @@
DROP TABLE `time_entry_tags`;--> statement-breakpoint
ALTER TABLE `time_entries` ADD `tag_id` text REFERENCES tags(id);--> statement-breakpoint
CREATE INDEX `time_entries_tag_id_idx` ON `time_entries` (`tag_id`);

View File

@@ -1,6 +0,0 @@
ALTER TABLE `clients` ADD `phone` text;--> statement-breakpoint
ALTER TABLE `clients` ADD `street` text;--> statement-breakpoint
ALTER TABLE `clients` ADD `city` text;--> statement-breakpoint
ALTER TABLE `clients` ADD `state` text;--> statement-breakpoint
ALTER TABLE `clients` ADD `zip` text;--> statement-breakpoint
ALTER TABLE `clients` ADD `country` text;

View File

@@ -1,16 +0,0 @@
CREATE INDEX `api_tokens_user_id_idx` ON `api_tokens` (`user_id`);--> statement-breakpoint
CREATE INDEX `categories_organization_id_idx` ON `categories` (`organization_id`);--> statement-breakpoint
CREATE INDEX `clients_organization_id_idx` ON `clients` (`organization_id`);--> statement-breakpoint
CREATE INDEX `invoice_items_invoice_id_idx` ON `invoice_items` (`invoice_id`);--> statement-breakpoint
CREATE INDEX `invoices_organization_id_idx` ON `invoices` (`organization_id`);--> statement-breakpoint
CREATE INDEX `invoices_client_id_idx` ON `invoices` (`client_id`);--> statement-breakpoint
CREATE INDEX `members_user_id_idx` ON `members` (`user_id`);--> statement-breakpoint
CREATE INDEX `members_organization_id_idx` ON `members` (`organization_id`);--> statement-breakpoint
CREATE INDEX `sessions_user_id_idx` ON `sessions` (`user_id`);--> statement-breakpoint
CREATE INDEX `tags_organization_id_idx` ON `tags` (`organization_id`);--> statement-breakpoint
CREATE INDEX `time_entries_user_id_idx` ON `time_entries` (`user_id`);--> statement-breakpoint
CREATE INDEX `time_entries_organization_id_idx` ON `time_entries` (`organization_id`);--> statement-breakpoint
CREATE INDEX `time_entries_client_id_idx` ON `time_entries` (`client_id`);--> statement-breakpoint
CREATE INDEX `time_entries_start_time_idx` ON `time_entries` (`start_time`);--> statement-breakpoint
CREATE INDEX `time_entry_tags_time_entry_id_idx` ON `time_entry_tags` (`time_entry_id`);--> statement-breakpoint
CREATE INDEX `time_entry_tags_tag_id_idx` ON `time_entry_tags` (`tag_id`);

View File

@@ -1,3 +0,0 @@
ALTER TABLE `invoices` ADD `discount_value` real DEFAULT 0;--> statement-breakpoint
ALTER TABLE `invoices` ADD `discount_type` text DEFAULT 'percentage';--> statement-breakpoint
ALTER TABLE `invoices` ADD `discount_amount` integer DEFAULT 0;

View File

@@ -1,22 +0,0 @@
CREATE TABLE `passkey_challenges` (
`id` text PRIMARY KEY NOT NULL,
`challenge` text NOT NULL,
`user_id` text,
`expires_at` integer NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `passkey_challenges_challenge_unique` ON `passkey_challenges` (`challenge`);--> statement-breakpoint
CREATE TABLE `passkeys` (
`id` text PRIMARY KEY NOT NULL,
`user_id` text NOT NULL,
`public_key` text NOT NULL,
`counter` integer NOT NULL,
`device_type` text NOT NULL,
`backed_up` integer NOT NULL,
`transports` text,
`last_used_at` integer,
`created_at` integer,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE INDEX `passkeys_user_id_idx` ON `passkeys` (`user_id`);

View File

@@ -1,7 +1,7 @@
{ {
"version": "6", "version": "6",
"dialect": "sqlite", "dialect": "sqlite",
"id": "e1e0fee4-786a-4f9f-9ebe-659aae0a55be", "id": "8343b003-264b-444a-9782-07d736dd3407",
"prevId": "00000000-0000-0000-0000-000000000000", "prevId": "00000000-0000-0000-0000-000000000000",
"tables": { "tables": {
"api_tokens": { "api_tokens": {
@@ -65,6 +65,13 @@
"token" "token"
], ],
"isUnique": true "isUnique": true
},
"api_tokens_user_id_idx": {
"name": "api_tokens_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
} }
}, },
"foreignKeys": { "foreignKeys": {
@@ -86,65 +93,6 @@
"uniqueConstraints": {}, "uniqueConstraints": {},
"checkConstraints": {} "checkConstraints": {}
}, },
"categories": {
"name": "categories",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"organization_id": {
"name": "organization_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"categories_organization_id_organizations_id_fk": {
"name": "categories_organization_id_organizations_id_fk",
"tableFrom": "categories",
"tableTo": "organizations",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"clients": { "clients": {
"name": "clients", "name": "clients",
"columns": { "columns": {
@@ -176,6 +124,48 @@
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"phone": {
"name": "phone",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"street": {
"name": "street",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"city": {
"name": "city",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"state": {
"name": "state",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"zip": {
"name": "zip",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"country": {
"name": "country",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": { "created_at": {
"name": "created_at", "name": "created_at",
"type": "integer", "type": "integer",
@@ -184,7 +174,15 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"clients_organization_id_idx": {
"name": "clients_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"clients_organization_id_organizations_id_fk": { "clients_organization_id_organizations_id_fk": {
"name": "clients_organization_id_organizations_id_fk", "name": "clients_organization_id_organizations_id_fk",
@@ -253,7 +251,15 @@
"default": 0 "default": 0
} }
}, },
"indexes": {}, "indexes": {
"invoice_items_invoice_id_idx": {
"name": "invoice_items_invoice_id_idx",
"columns": [
"invoice_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"invoice_items_invoice_id_invoices_id_fk": { "invoice_items_invoice_id_invoices_id_fk": {
"name": "invoice_items_invoice_id_invoices_id_fk", "name": "invoice_items_invoice_id_invoices_id_fk",
@@ -357,6 +363,30 @@
"autoincrement": false, "autoincrement": false,
"default": 0 "default": 0
}, },
"discount_value": {
"name": "discount_value",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"discount_type": {
"name": "discount_type",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "'percentage'"
},
"discount_amount": {
"name": "discount_amount",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"tax_rate": { "tax_rate": {
"name": "tax_rate", "name": "tax_rate",
"type": "real", "type": "real",
@@ -389,7 +419,22 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"invoices_organization_id_idx": {
"name": "invoices_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
},
"invoices_client_id_idx": {
"name": "invoices_client_id_idx",
"columns": [
"client_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"invoices_organization_id_organizations_id_fk": { "invoices_organization_id_organizations_id_fk": {
"name": "invoices_organization_id_organizations_id_fk", "name": "invoices_organization_id_organizations_id_fk",
@@ -455,7 +500,22 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"members_user_id_idx": {
"name": "members_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
},
"members_organization_id_idx": {
"name": "members_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"members_user_id_users_id_fk": { "members_user_id_users_id_fk": {
"name": "members_user_id_users_id_fk", "name": "members_user_id_users_id_fk",
@@ -555,6 +615,22 @@
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"default_tax_rate": {
"name": "default_tax_rate",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"default_currency": {
"name": "default_currency",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "'USD'"
},
"created_at": { "created_at": {
"name": "created_at", "name": "created_at",
"type": "integer", "type": "integer",
@@ -569,6 +645,147 @@
"uniqueConstraints": {}, "uniqueConstraints": {},
"checkConstraints": {} "checkConstraints": {}
}, },
"passkey_challenges": {
"name": "passkey_challenges",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"challenge": {
"name": "challenge",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"passkey_challenges_challenge_unique": {
"name": "passkey_challenges_challenge_unique",
"columns": [
"challenge"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"passkeys": {
"name": "passkeys",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"public_key": {
"name": "public_key",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"counter": {
"name": "counter",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"device_type": {
"name": "device_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"backed_up": {
"name": "backed_up",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"transports": {
"name": "transports",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"last_used_at": {
"name": "last_used_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"passkeys_user_id_idx": {
"name": "passkeys_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
}
},
"foreignKeys": {
"passkeys_user_id_users_id_fk": {
"name": "passkeys_user_id_users_id_fk",
"tableFrom": "passkeys",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"sessions": { "sessions": {
"name": "sessions", "name": "sessions",
"columns": { "columns": {
@@ -594,7 +811,15 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"sessions_user_id_idx": {
"name": "sessions_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"sessions_user_id_users_id_fk": { "sessions_user_id_users_id_fk": {
"name": "sessions_user_id_users_id_fk", "name": "sessions_user_id_users_id_fk",
@@ -691,6 +916,14 @@
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"rate": {
"name": "rate",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"created_at": { "created_at": {
"name": "created_at", "name": "created_at",
"type": "integer", "type": "integer",
@@ -699,7 +932,15 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"tags_organization_id_idx": {
"name": "tags_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"tags_organization_id_organizations_id_fk": { "tags_organization_id_organizations_id_fk": {
"name": "tags_organization_id_organizations_id_fk", "name": "tags_organization_id_organizations_id_fk",
@@ -750,13 +991,6 @@
"notNull": true, "notNull": true,
"autoincrement": false "autoincrement": false
}, },
"category_id": {
"name": "category_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"start_time": { "start_time": {
"name": "start_time", "name": "start_time",
"type": "integer", "type": "integer",
@@ -778,6 +1012,13 @@
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"invoice_id": {
"name": "invoice_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"is_manual": { "is_manual": {
"name": "is_manual", "name": "is_manual",
"type": "integer", "type": "integer",
@@ -794,7 +1035,43 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"time_entries_user_id_idx": {
"name": "time_entries_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
},
"time_entries_organization_id_idx": {
"name": "time_entries_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
},
"time_entries_client_id_idx": {
"name": "time_entries_client_id_idx",
"columns": [
"client_id"
],
"isUnique": false
},
"time_entries_start_time_idx": {
"name": "time_entries_start_time_idx",
"columns": [
"start_time"
],
"isUnique": false
},
"time_entries_invoice_id_idx": {
"name": "time_entries_invoice_id_idx",
"columns": [
"invoice_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"time_entries_user_id_users_id_fk": { "time_entries_user_id_users_id_fk": {
"name": "time_entries_user_id_users_id_fk", "name": "time_entries_user_id_users_id_fk",
@@ -834,19 +1111,6 @@
], ],
"onDelete": "no action", "onDelete": "no action",
"onUpdate": "no action" "onUpdate": "no action"
},
"time_entries_category_id_categories_id_fk": {
"name": "time_entries_category_id_categories_id_fk",
"tableFrom": "time_entries",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
} }
}, },
"compositePrimaryKeys": {}, "compositePrimaryKeys": {},
@@ -871,7 +1135,22 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"time_entry_tags_time_entry_id_idx": {
"name": "time_entry_tags_time_entry_id_idx",
"columns": [
"time_entry_id"
],
"isUnique": false
},
"time_entry_tags_tag_id_idx": {
"name": "time_entry_tags_tag_id_idx",
"columns": [
"tag_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"time_entry_tags_time_entry_id_time_entries_id_fk": { "time_entry_tags_time_entry_id_time_entries_id_fk": {
"name": "time_entry_tags_time_entry_id_time_entries_id_fk", "name": "time_entry_tags_time_entry_id_time_entries_id_fk",

View File

@@ -1,8 +1,8 @@
{ {
"version": "6", "version": "6",
"dialect": "sqlite", "dialect": "sqlite",
"id": "5483c77e-e742-4fbd-8494-d6f9c6c9e28a", "id": "837a4e18-b319-465d-9e30-2614b4850fb5",
"prevId": "e1e0fee4-786a-4f9f-9ebe-659aae0a55be", "prevId": "8343b003-264b-444a-9782-07d736dd3407",
"tables": { "tables": {
"api_tokens": { "api_tokens": {
"name": "api_tokens", "name": "api_tokens",
@@ -65,6 +65,13 @@
"token" "token"
], ],
"isUnique": true "isUnique": true
},
"api_tokens_user_id_idx": {
"name": "api_tokens_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
} }
}, },
"foreignKeys": { "foreignKeys": {
@@ -86,65 +93,6 @@
"uniqueConstraints": {}, "uniqueConstraints": {},
"checkConstraints": {} "checkConstraints": {}
}, },
"categories": {
"name": "categories",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"organization_id": {
"name": "organization_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"categories_organization_id_organizations_id_fk": {
"name": "categories_organization_id_organizations_id_fk",
"tableFrom": "categories",
"tableTo": "organizations",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"clients": { "clients": {
"name": "clients", "name": "clients",
"columns": { "columns": {
@@ -226,7 +174,15 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"clients_organization_id_idx": {
"name": "clients_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"clients_organization_id_organizations_id_fk": { "clients_organization_id_organizations_id_fk": {
"name": "clients_organization_id_organizations_id_fk", "name": "clients_organization_id_organizations_id_fk",
@@ -295,7 +251,15 @@
"default": 0 "default": 0
} }
}, },
"indexes": {}, "indexes": {
"invoice_items_invoice_id_idx": {
"name": "invoice_items_invoice_id_idx",
"columns": [
"invoice_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"invoice_items_invoice_id_invoices_id_fk": { "invoice_items_invoice_id_invoices_id_fk": {
"name": "invoice_items_invoice_id_invoices_id_fk", "name": "invoice_items_invoice_id_invoices_id_fk",
@@ -399,6 +363,30 @@
"autoincrement": false, "autoincrement": false,
"default": 0 "default": 0
}, },
"discount_value": {
"name": "discount_value",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"discount_type": {
"name": "discount_type",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "'percentage'"
},
"discount_amount": {
"name": "discount_amount",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"tax_rate": { "tax_rate": {
"name": "tax_rate", "name": "tax_rate",
"type": "real", "type": "real",
@@ -431,7 +419,22 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"invoices_organization_id_idx": {
"name": "invoices_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
},
"invoices_client_id_idx": {
"name": "invoices_client_id_idx",
"columns": [
"client_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"invoices_organization_id_organizations_id_fk": { "invoices_organization_id_organizations_id_fk": {
"name": "invoices_organization_id_organizations_id_fk", "name": "invoices_organization_id_organizations_id_fk",
@@ -497,7 +500,22 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"members_user_id_idx": {
"name": "members_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
},
"members_organization_id_idx": {
"name": "members_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"members_user_id_users_id_fk": { "members_user_id_users_id_fk": {
"name": "members_user_id_users_id_fk", "name": "members_user_id_users_id_fk",
@@ -597,6 +615,22 @@
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"default_tax_rate": {
"name": "default_tax_rate",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"default_currency": {
"name": "default_currency",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "'USD'"
},
"created_at": { "created_at": {
"name": "created_at", "name": "created_at",
"type": "integer", "type": "integer",
@@ -611,6 +645,147 @@
"uniqueConstraints": {}, "uniqueConstraints": {},
"checkConstraints": {} "checkConstraints": {}
}, },
"passkey_challenges": {
"name": "passkey_challenges",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"challenge": {
"name": "challenge",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"passkey_challenges_challenge_unique": {
"name": "passkey_challenges_challenge_unique",
"columns": [
"challenge"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"passkeys": {
"name": "passkeys",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"public_key": {
"name": "public_key",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"counter": {
"name": "counter",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"device_type": {
"name": "device_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"backed_up": {
"name": "backed_up",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"transports": {
"name": "transports",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"last_used_at": {
"name": "last_used_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"passkeys_user_id_idx": {
"name": "passkeys_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
}
},
"foreignKeys": {
"passkeys_user_id_users_id_fk": {
"name": "passkeys_user_id_users_id_fk",
"tableFrom": "passkeys",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"sessions": { "sessions": {
"name": "sessions", "name": "sessions",
"columns": { "columns": {
@@ -636,7 +811,15 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"sessions_user_id_idx": {
"name": "sessions_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"sessions_user_id_users_id_fk": { "sessions_user_id_users_id_fk": {
"name": "sessions_user_id_users_id_fk", "name": "sessions_user_id_users_id_fk",
@@ -733,6 +916,14 @@
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"rate": {
"name": "rate",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"created_at": { "created_at": {
"name": "created_at", "name": "created_at",
"type": "integer", "type": "integer",
@@ -741,7 +932,15 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"tags_organization_id_idx": {
"name": "tags_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"tags_organization_id_organizations_id_fk": { "tags_organization_id_organizations_id_fk": {
"name": "tags_organization_id_organizations_id_fk", "name": "tags_organization_id_organizations_id_fk",
@@ -792,11 +991,11 @@
"notNull": true, "notNull": true,
"autoincrement": false "autoincrement": false
}, },
"category_id": { "tag_id": {
"name": "category_id", "name": "tag_id",
"type": "text", "type": "text",
"primaryKey": false, "primaryKey": false,
"notNull": true, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"start_time": { "start_time": {
@@ -820,6 +1019,13 @@
"notNull": false, "notNull": false,
"autoincrement": false "autoincrement": false
}, },
"invoice_id": {
"name": "invoice_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"is_manual": { "is_manual": {
"name": "is_manual", "name": "is_manual",
"type": "integer", "type": "integer",
@@ -836,7 +1042,50 @@
"autoincrement": false "autoincrement": false
} }
}, },
"indexes": {}, "indexes": {
"time_entries_user_id_idx": {
"name": "time_entries_user_id_idx",
"columns": [
"user_id"
],
"isUnique": false
},
"time_entries_organization_id_idx": {
"name": "time_entries_organization_id_idx",
"columns": [
"organization_id"
],
"isUnique": false
},
"time_entries_client_id_idx": {
"name": "time_entries_client_id_idx",
"columns": [
"client_id"
],
"isUnique": false
},
"time_entries_tag_id_idx": {
"name": "time_entries_tag_id_idx",
"columns": [
"tag_id"
],
"isUnique": false
},
"time_entries_start_time_idx": {
"name": "time_entries_start_time_idx",
"columns": [
"start_time"
],
"isUnique": false
},
"time_entries_invoice_id_idx": {
"name": "time_entries_invoice_id_idx",
"columns": [
"invoice_id"
],
"isUnique": false
}
},
"foreignKeys": { "foreignKeys": {
"time_entries_user_id_users_id_fk": { "time_entries_user_id_users_id_fk": {
"name": "time_entries_user_id_users_id_fk", "name": "time_entries_user_id_users_id_fk",
@@ -877,60 +1126,9 @@
"onDelete": "no action", "onDelete": "no action",
"onUpdate": "no action" "onUpdate": "no action"
}, },
"time_entries_category_id_categories_id_fk": { "time_entries_tag_id_tags_id_fk": {
"name": "time_entries_category_id_categories_id_fk", "name": "time_entries_tag_id_tags_id_fk",
"tableFrom": "time_entries", "tableFrom": "time_entries",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"time_entry_tags": {
"name": "time_entry_tags",
"columns": {
"time_entry_id": {
"name": "time_entry_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"tag_id": {
"name": "tag_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"time_entry_tags_time_entry_id_time_entries_id_fk": {
"name": "time_entry_tags_time_entry_id_time_entries_id_fk",
"tableFrom": "time_entry_tags",
"tableTo": "time_entries",
"columnsFrom": [
"time_entry_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"time_entry_tags_tag_id_tags_id_fk": {
"name": "time_entry_tags_tag_id_tags_id_fk",
"tableFrom": "time_entry_tags",
"tableTo": "tags", "tableTo": "tags",
"columnsFrom": [ "columnsFrom": [
"tag_id" "tag_id"
@@ -942,15 +1140,7 @@
"onUpdate": "no action" "onUpdate": "no action"
} }
}, },
"compositePrimaryKeys": { "compositePrimaryKeys": {},
"time_entry_tags_time_entry_id_tag_id_pk": {
"columns": [
"time_entry_id",
"tag_id"
],
"name": "time_entry_tags_time_entry_id_tag_id_pk"
}
},
"uniqueConstraints": {}, "uniqueConstraints": {},
"checkConstraints": {} "checkConstraints": {}
}, },

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -5,36 +5,15 @@
{ {
"idx": 0, "idx": 0,
"version": "6", "version": "6",
"when": 1768688193284, "when": 1768934194146,
"tag": "0000_motionless_king_cobra", "tag": "0000_lazy_rictor",
"breakpoints": true "breakpoints": true
}, },
{ {
"idx": 1, "idx": 1,
"version": "6", "version": "6",
"when": 1768690333269, "when": 1768935234392,
"tag": "0001_lazy_roughhouse", "tag": "0001_demonic_red_skull",
"breakpoints": true
},
{
"idx": 2,
"version": "6",
"when": 1768773436601,
"tag": "0002_chilly_cyclops",
"breakpoints": true
},
{
"idx": 3,
"version": "6",
"when": 1768842088321,
"tag": "0003_amusing_wendigo",
"breakpoints": true
},
{
"idx": 4,
"version": "6",
"when": 1768876902359,
"tag": "0004_happy_namorita",
"breakpoints": true "breakpoints": true
} }
] ]

View File

@@ -1,7 +1,7 @@
{ {
"name": "chronus", "name": "chronus",
"type": "module", "type": "module",
"version": "2.2.1", "version": "2.4.0",
"scripts": { "scripts": {
"dev": "astro dev", "dev": "astro dev",
"build": "astro build", "build": "astro build",
@@ -12,32 +12,32 @@
"migrate": "node scripts/migrate.js" "migrate": "node scripts/migrate.js"
}, },
"dependencies": { "dependencies": {
"@astrojs/check": "^0.9.6", "@astrojs/check": "0.9.6",
"@astrojs/node": "^9.5.2", "@astrojs/node": "10.0.0-beta.2",
"@astrojs/vue": "^5.1.4", "@astrojs/vue": "6.0.0-beta.0",
"@ceereals/vue-pdf": "^0.2.1", "@ceereals/vue-pdf": "^0.2.1",
"@iconify/vue": "^5.0.0", "@iconify/vue": "^5.0.0",
"@libsql/client": "^0.17.0", "@libsql/client": "^0.17.0",
"@simplewebauthn/browser": "^13.2.2", "@simplewebauthn/browser": "^13.2.2",
"@simplewebauthn/server": "^13.2.2", "@simplewebauthn/server": "^13.2.2",
"@tailwindcss/vite": "^4.1.18", "@tailwindcss/vite": "^4.1.18",
"astro": "^5.16.11", "astro": "6.0.0-beta.9",
"astro-icon": "^1.1.5", "astro-icon": "^1.1.5",
"bcryptjs": "^3.0.3", "bcryptjs": "^3.0.3",
"chart.js": "^4.5.1", "chart.js": "^4.5.1",
"daisyui": "^5.5.14", "daisyui": "^5.5.18",
"dotenv": "^17.2.3", "dotenv": "^17.2.4",
"drizzle-orm": "0.45.1", "drizzle-orm": "0.45.1",
"nanoid": "^5.1.6", "nanoid": "^5.1.6",
"tailwindcss": "^4.1.18", "tailwindcss": "^4.1.18",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"vue": "^3.5.27", "vue": "^3.5.28",
"vue-chartjs": "^5.3.3" "vue-chartjs": "^5.3.3"
}, },
"devDependencies": { "devDependencies": {
"@catppuccin/daisyui": "^2.1.1", "@catppuccin/daisyui": "^2.1.1",
"@iconify-json/heroicons": "^1.2.3", "@iconify-json/heroicons": "^1.2.3",
"@react-pdf/types": "^2.9.2", "@react-pdf/types": "^2.9.2",
"drizzle-kit": "0.31.8" "drizzle-kit": "0.31.9"
} }
} }

1568
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@ const initial = name ? name.charAt(0).toUpperCase() : '?';
--- ---
<div class:list={["avatar placeholder", className]}> <div class:list={["avatar placeholder", className]}>
<div class="bg-primary text-primary-content w-10 rounded-full flex items-center justify-center"> <div class="bg-primary/15 text-primary w-9 h-9 rounded-full flex items-center justify-center">
<span class="text-lg font-semibold">{initial}</span> <span class="text-sm font-semibold">{initial}</span>
</div> </div>
</div> </div>

View File

@@ -1,64 +0,0 @@
<template>
<div style="position: relative; height: 100%; width: 100%;">
<Doughnut :data="chartData" :options="chartOptions" />
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { Doughnut } from 'vue-chartjs';
import {
Chart as ChartJS,
ArcElement,
Tooltip,
Legend,
DoughnutController
} from 'chart.js';
ChartJS.register(ArcElement, Tooltip, Legend, DoughnutController);
interface CategoryData {
name: string;
totalTime: number;
color: string;
}
const props = defineProps<{
categories: CategoryData[];
}>();
const chartData = computed(() => ({
labels: props.categories.map(c => c.name),
datasets: [{
data: props.categories.map(c => c.totalTime),
backgroundColor: props.categories.map(c => c.color || '#3b82f6'),
borderWidth: 2,
borderColor: '#1e293b',
}]
}));
const chartOptions = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom' as const,
labels: {
color: '#e2e8f0',
padding: 15,
font: { size: 12 }
}
},
tooltip: {
callbacks: {
label: function(context: any) {
const minutes = Math.round(context.raw / (1000 * 60));
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
return ` ${context.label}: ${hours}h ${mins}m`;
}
}
}
}
};
</script>

View File

@@ -3,7 +3,6 @@ import { ref } from "vue";
const props = defineProps<{ const props = defineProps<{
clients: { id: string; name: string }[]; clients: { id: string; name: string }[];
categories: { id: string; name: string; color: string | null }[];
tags: { id: string; name: string; color: string | null }[]; tags: { id: string; name: string; color: string | null }[];
}>(); }>();
@@ -13,8 +12,7 @@ const emit = defineEmits<{
const description = ref(""); const description = ref("");
const selectedClientId = ref(""); const selectedClientId = ref("");
const selectedCategoryId = ref(""); const selectedTagId = ref<string | null>(null);
const selectedTags = ref<string[]>([]);
const startDate = ref(""); const startDate = ref("");
const startTime = ref(""); const startTime = ref("");
const endDate = ref(""); const endDate = ref("");
@@ -28,11 +26,10 @@ startDate.value = today;
endDate.value = today; endDate.value = today;
function toggleTag(tagId: string) { function toggleTag(tagId: string) {
const index = selectedTags.value.indexOf(tagId); if (selectedTagId.value === tagId) {
if (index > -1) { selectedTagId.value = null;
selectedTags.value.splice(index, 1);
} else { } else {
selectedTags.value.push(tagId); selectedTagId.value = tagId;
} }
} }
@@ -53,10 +50,6 @@ function validateForm(): string | null {
return "Please select a client"; return "Please select a client";
} }
if (!selectedCategoryId.value) {
return "Please select a category";
}
if (!startDate.value || !startTime.value) { if (!startDate.value || !startTime.value) {
return "Please enter start date and time"; return "Please enter start date and time";
} }
@@ -101,10 +94,9 @@ async function submitManualEntry() {
body: JSON.stringify({ body: JSON.stringify({
description: description.value, description: description.value,
clientId: selectedClientId.value, clientId: selectedClientId.value,
categoryId: selectedCategoryId.value,
startTime: startDateTime, startTime: startDateTime,
endTime: endDateTime, endTime: endDateTime,
tags: selectedTags.value, tagId: selectedTagId.value,
}), }),
}); });
@@ -119,8 +111,7 @@ async function submitManualEntry() {
description.value = ""; description.value = "";
selectedClientId.value = ""; selectedClientId.value = "";
selectedCategoryId.value = ""; selectedTagId.value = null;
selectedTags.value = [];
startDate.value = today; startDate.value = today;
endDate.value = today; endDate.value = today;
startTime.value = ""; startTime.value = "";
@@ -144,8 +135,7 @@ async function submitManualEntry() {
function clearForm() { function clearForm() {
description.value = ""; description.value = "";
selectedClientId.value = ""; selectedClientId.value = "";
selectedCategoryId.value = ""; selectedTagId.value = null;
selectedTags.value = [];
startDate.value = today; startDate.value = today;
endDate.value = today; endDate.value = today;
startTime.value = ""; startTime.value = "";
@@ -208,59 +198,32 @@ function clearForm() {
<span>{{ error }}</span> <span>{{ error }}</span>
</div> </div>
<!-- Client and Category Row --> <!-- Client Row -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6"> <div class="form-control">
<div class="form-control"> <label class="label pb-2 font-medium" for="manual-client">
<label class="label pb-2"> Client <span class="label-text-alt text-error">*</span>
<span class="label-text font-medium">Client</span> </label>
<span class="label-text-alt text-error">*</span> <select
</label> id="manual-client"
<select v-model="selectedClientId"
v-model="selectedClientId" class="select select-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
class="select select-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors" :disabled="isSubmitting"
:disabled="isSubmitting" >
> <option value="">Select a client...</option>
<option value="">Select a client...</option> <option v-for="client in clients" :key="client.id" :value="client.id">
<option {{ client.name }}
v-for="client in clients" </option>
:key="client.id" </select>
:value="client.id"
>
{{ client.name }}
</option>
</select>
</div>
<div class="form-control">
<label class="label pb-2">
<span class="label-text font-medium">Category</span>
<span class="label-text-alt text-error">*</span>
</label>
<select
v-model="selectedCategoryId"
class="select select-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
:disabled="isSubmitting"
>
<option value="">Select a category...</option>
<option
v-for="category in categories"
:key="category.id"
:value="category.id"
>
{{ category.name }}
</option>
</select>
</div>
</div> </div>
<!-- Start Date and Time --> <!-- Start Date and Time -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6"> <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="manual-start-date">
<span class="label-text font-medium">Start Date</span> Start Date <span class="label-text-alt text-error">*</span>
<span class="label-text-alt text-error">*</span>
</label> </label>
<input <input
id="manual-start-date"
v-model="startDate" v-model="startDate"
type="date" type="date"
class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors" class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
@@ -269,11 +232,11 @@ function clearForm() {
</div> </div>
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="manual-start-time">
<span class="label-text font-medium">Start Time</span> Start Time <span class="label-text-alt text-error">*</span>
<span class="label-text-alt text-error">*</span>
</label> </label>
<input <input
id="manual-start-time"
v-model="startTime" v-model="startTime"
type="time" type="time"
class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors" class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
@@ -285,11 +248,11 @@ function clearForm() {
<!-- End Date and Time --> <!-- End Date and Time -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6"> <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="manual-end-date">
<span class="label-text font-medium">End Date</span> End Date <span class="label-text-alt text-error">*</span>
<span class="label-text-alt text-error">*</span>
</label> </label>
<input <input
id="manual-end-date"
v-model="endDate" v-model="endDate"
type="date" type="date"
class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors" class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
@@ -298,11 +261,11 @@ function clearForm() {
</div> </div>
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="manual-end-time">
<span class="label-text font-medium">End Time</span> End Time <span class="label-text-alt text-error">*</span>
<span class="label-text-alt text-error">*</span>
</label> </label>
<input <input
id="manual-end-time"
v-model="endTime" v-model="endTime"
type="time" type="time"
class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors" class="input input-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
@@ -313,10 +276,11 @@ function clearForm() {
<!-- Description Row --> <!-- Description Row -->
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="manual-description">
<span class="label-text font-medium">Description</span> Description
</label> </label>
<input <input
id="manual-description"
v-model="description" v-model="description"
type="text" type="text"
placeholder="What did you work on?" placeholder="What did you work on?"
@@ -327,9 +291,7 @@ function clearForm() {
<!-- Tags Section --> <!-- Tags Section -->
<div v-if="tags.length > 0" class="form-control"> <div v-if="tags.length > 0" class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="manual-tags"> Tags </label>
<span class="label-text font-medium">Tags</span>
</label>
<div class="flex flex-wrap gap-2"> <div class="flex flex-wrap gap-2">
<button <button
v-for="tag in tags" v-for="tag in tags"
@@ -337,7 +299,7 @@ function clearForm() {
@click="toggleTag(tag.id)" @click="toggleTag(tag.id)"
:class="[ :class="[
'badge badge-lg cursor-pointer transition-all hover:scale-105', 'badge badge-lg cursor-pointer transition-all hover:scale-105',
selectedTags.includes(tag.id) selectedTagId === tag.id
? 'badge-primary shadow-lg shadow-primary/20' ? 'badge-primary shadow-lg shadow-primary/20'
: 'badge-outline hover:bg-base-300/50', : 'badge-outline hover:bg-base-300/50',
]" ]"

View File

@@ -0,0 +1,29 @@
---
import { Icon } from 'astro-icon/components';
interface Props {
title: string;
value: string;
description?: string;
icon?: string;
color?: string;
valueClass?: string;
}
const { title, value, description, icon, color = 'text-primary', valueClass } = Astro.props;
---
<div class="card card-border bg-base-100">
<div class="card-body p-4 gap-1">
<div class="flex items-center justify-between">
<span class="text-xs font-medium uppercase tracking-wider text-base-content/60">{title}</span>
{icon && (
<div class:list={[color, "opacity-40"]}>
<Icon name={icon} class="w-5 h-5" />
</div>
)}
</div>
<div class:list={["text-2xl font-bold", color, valueClass]}>{value}</div>
{description && <div class="text-xs text-base-content/50">{description}</div>}
</div>
</div>

View File

@@ -0,0 +1,67 @@
<template>
<div style="position: relative; height: 100%; width: 100%">
<Doughnut :data="chartData" :options="chartOptions" />
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
import { Doughnut } from "vue-chartjs";
import {
Chart as ChartJS,
ArcElement,
Tooltip,
Legend,
type ChartOptions,
} from "chart.js";
ChartJS.register(ArcElement, Tooltip, Legend);
interface TagData {
name: string;
totalTime: number;
color: string;
}
const props = defineProps<{
tags: TagData[];
}>();
const chartData = computed(() => ({
labels: props.tags.map((t) => t.name),
datasets: [
{
data: props.tags.map((t) => t.totalTime / (1000 * 60)), // Convert to minutes
backgroundColor: props.tags.map((t) => t.color),
borderColor: "#1e293b", // Matches typical dark mode bg
borderWidth: 2,
},
],
}));
const chartOptions: ChartOptions<"doughnut"> = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: "right",
labels: {
color: "#e2e8f0",
usePointStyle: true,
padding: 20,
},
},
tooltip: {
callbacks: {
label: function (context) {
const minutes = Math.round(context.raw as number);
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
return ` ${hours}h ${mins}m`;
},
},
},
},
cutout: "70%",
};
</script>

View File

@@ -0,0 +1,34 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { Icon } from '@iconify/vue';
const theme = ref('macchiato');
onMounted(() => {
const stored = localStorage.getItem('theme');
if (stored) {
theme.value = stored;
document.documentElement.setAttribute('data-theme', stored);
}
});
function toggleTheme() {
const newTheme = theme.value === 'macchiato' ? 'latte' : 'macchiato';
theme.value = newTheme;
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
}
</script>
<template>
<button
@click="toggleTheme"
class="btn btn-ghost btn-circle"
aria-label="Toggle Theme"
>
<Icon
:icon="theme === 'macchiato' ? 'heroicons:moon' : 'heroicons:sun'"
class="w-5 h-5"
/>
</button>
</template>

View File

@@ -7,10 +7,9 @@ const props = defineProps<{
startTime: number; startTime: number;
description: string | null; description: string | null;
clientId: string; clientId: string;
categoryId: string; tagId?: string;
} | null; } | null;
clients: { id: string; name: string }[]; clients: { id: string; name: string }[];
categories: { id: string; name: string; color: string | null }[];
tags: { id: string; name: string; color: string | null }[]; tags: { id: string; name: string; color: string | null }[];
}>(); }>();
@@ -19,8 +18,7 @@ const startTime = ref<number | null>(null);
const elapsedTime = ref(0); const elapsedTime = ref(0);
const description = ref(""); const description = ref("");
const selectedClientId = ref(""); const selectedClientId = ref("");
const selectedCategoryId = ref(""); const selectedTagId = ref<string | null>(null);
const selectedTags = ref<string[]>([]);
let interval: ReturnType<typeof setInterval> | null = null; let interval: ReturnType<typeof setInterval> | null = null;
function formatTime(ms: number) { function formatTime(ms: number) {
@@ -49,11 +47,10 @@ function formatTime(ms: number) {
} }
function toggleTag(tagId: string) { function toggleTag(tagId: string) {
const index = selectedTags.value.indexOf(tagId); if (selectedTagId.value === tagId) {
if (index > -1) { selectedTagId.value = null;
selectedTags.value.splice(index, 1);
} else { } else {
selectedTags.value.push(tagId); selectedTagId.value = tagId;
} }
} }
@@ -63,7 +60,7 @@ onMounted(() => {
startTime.value = props.initialRunningEntry.startTime; startTime.value = props.initialRunningEntry.startTime;
description.value = props.initialRunningEntry.description || ""; description.value = props.initialRunningEntry.description || "";
selectedClientId.value = props.initialRunningEntry.clientId; selectedClientId.value = props.initialRunningEntry.clientId;
selectedCategoryId.value = props.initialRunningEntry.categoryId; selectedTagId.value = props.initialRunningEntry.tagId || null;
elapsedTime.value = Date.now() - startTime.value; elapsedTime.value = Date.now() - startTime.value;
interval = setInterval(() => { interval = setInterval(() => {
elapsedTime.value = Date.now() - startTime.value!; elapsedTime.value = Date.now() - startTime.value!;
@@ -81,19 +78,13 @@ async function startTimer() {
return; return;
} }
if (!selectedCategoryId.value) {
alert("Please select a category");
return;
}
const res = await fetch("/api/time-entries/start", { const res = await fetch("/api/time-entries/start", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
description: description.value, description: description.value,
clientId: selectedClientId.value, clientId: selectedClientId.value,
categoryId: selectedCategoryId.value, tagId: selectedTagId.value,
tags: selectedTags.value,
}), }),
}); });
@@ -119,8 +110,7 @@ async function stopTimer() {
startTime.value = null; startTime.value = null;
description.value = ""; description.value = "";
selectedClientId.value = ""; selectedClientId.value = "";
selectedCategoryId.value = ""; selectedTagId.value = null;
selectedTags.value = [];
window.location.reload(); window.location.reload();
} }
} }
@@ -131,55 +121,31 @@ async function stopTimer() {
class="card bg-base-200/50 backdrop-blur-sm shadow-lg border border-base-300/50 mb-6 hover:border-base-300 transition-all duration-200" class="card bg-base-200/50 backdrop-blur-sm shadow-lg border border-base-300/50 mb-6 hover:border-base-300 transition-all duration-200"
> >
<div class="card-body gap-6"> <div class="card-body gap-6">
<!-- Client and Description Row --> <!-- Client Row -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6"> <div class="form-control">
<div class="form-control"> <label class="label pb-2 font-medium" for="timer-client">
<label class="label pb-2"> Client
<span class="label-text font-medium">Client</span> </label>
</label> <select
<select id="timer-client"
v-model="selectedClientId" v-model="selectedClientId"
class="select select-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors" class="select select-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
:disabled="isRunning" :disabled="isRunning"
> >
<option value="">Select a client...</option> <option value="">Select a client...</option>
<option <option v-for="client in clients" :key="client.id" :value="client.id">
v-for="client in clients" {{ client.name }}
:key="client.id" </option>
:value="client.id" </select>
>
{{ client.name }}
</option>
</select>
</div>
<div class="form-control">
<label class="label pb-2">
<span class="label-text font-medium">Category</span>
</label>
<select
v-model="selectedCategoryId"
class="select select-bordered w-full bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors"
:disabled="isRunning"
>
<option value="">Select a category...</option>
<option
v-for="category in categories"
:key="category.id"
:value="category.id"
>
{{ category.name }}
</option>
</select>
</div>
</div> </div>
<!-- Description Row --> <!-- Description Row -->
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="timer-description">
<span class="label-text font-medium">Description</span> Description
</label> </label>
<input <input
id="timer-description"
v-model="description" v-model="description"
type="text" type="text"
placeholder="What are you working on?" placeholder="What are you working on?"
@@ -190,9 +156,7 @@ async function stopTimer() {
<!-- Tags Section --> <!-- Tags Section -->
<div v-if="tags.length > 0" class="form-control"> <div v-if="tags.length > 0" class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="timer-tags"> Tags </label>
<span class="label-text font-medium">Tags</span>
</label>
<div class="flex flex-wrap gap-2"> <div class="flex flex-wrap gap-2">
<button <button
v-for="tag in tags" v-for="tag in tags"
@@ -200,7 +164,7 @@ async function stopTimer() {
@click="toggleTag(tag.id)" @click="toggleTag(tag.id)"
:class="[ :class="[
'badge badge-lg cursor-pointer transition-all hover:scale-105', 'badge badge-lg cursor-pointer transition-all hover:scale-105',
selectedTags.includes(tag.id) selectedTagId === tag.id
? 'badge-primary shadow-lg shadow-primary/20' ? 'badge-primary shadow-lg shadow-primary/20'
: 'badge-outline hover:bg-base-300/50', : 'badge-outline hover:bg-base-300/50',
]" ]"

View File

@@ -182,11 +182,12 @@ function closeShowTokenModal() {
<form @submit.prevent="createToken" class="space-y-4"> <form @submit.prevent="createToken" class="space-y-4">
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label class="label pb-2 font-medium" for="token-name">
<span class="label-text font-medium">Token Name</span> Token Name
</label> </label>
<input <input
type="text" type="text"
id="token-name"
v-model="newTokenName" v-model="newTokenName"
placeholder="e.g. CI/CD Pipeline" placeholder="e.g. CI/CD Pipeline"
class="input input-bordered w-full" class="input input-bordered w-full"

View File

@@ -1,21 +1,24 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from "vue";
import { Icon } from '@iconify/vue'; import { Icon } from "@iconify/vue";
const currentPassword = ref(''); const currentPassword = ref("");
const newPassword = ref(''); const newPassword = ref("");
const confirmPassword = ref(''); const confirmPassword = ref("");
const loading = ref(false); const loading = ref(false);
const message = ref<{ type: 'success' | 'error'; text: string } | null>(null); const message = ref<{ type: "success" | "error"; text: string } | null>(null);
async function changePassword() { async function changePassword() {
if (newPassword.value !== confirmPassword.value) { if (newPassword.value !== confirmPassword.value) {
message.value = { type: 'error', text: 'New passwords do not match' }; message.value = { type: "error", text: "New passwords do not match" };
return; return;
} }
if (newPassword.value.length < 8) { if (newPassword.value.length < 8) {
message.value = { type: 'error', text: 'Password must be at least 8 characters' }; message.value = {
type: "error",
text: "Password must be at least 8 characters",
};
return; return;
} }
@@ -23,10 +26,10 @@ async function changePassword() {
message.value = null; message.value = null;
try { try {
const response = await fetch('/api/user/change-password', { const response = await fetch("/api/user/change-password", {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
currentPassword: currentPassword.value, currentPassword: currentPassword.value,
@@ -36,20 +39,26 @@ async function changePassword() {
}); });
if (response.ok) { if (response.ok) {
message.value = { type: 'success', text: 'Password changed successfully!' }; message.value = {
currentPassword.value = ''; type: "success",
newPassword.value = ''; text: "Password changed successfully!",
confirmPassword.value = ''; };
currentPassword.value = "";
newPassword.value = "";
confirmPassword.value = "";
setTimeout(() => { setTimeout(() => {
message.value = null; message.value = null;
}, 3000); }, 3000);
} else { } else {
const data = await response.json().catch(() => ({})); const data = await response.json().catch(() => ({}));
message.value = { type: 'error', text: data.error || 'Failed to change password' }; message.value = {
type: "error",
text: data.error || "Failed to change password",
};
} }
} catch (error) { } catch (error) {
message.value = { type: 'error', text: 'An error occurred' }; message.value = { type: "error", text: "An error occurred" };
} finally { } finally {
loading.value = false; loading.value = false;
} }
@@ -59,8 +68,21 @@ async function changePassword() {
<template> <template>
<div> <div>
<!-- Success/Error Message Display --> <!-- Success/Error Message Display -->
<div v-if="message" :class="['alert mb-6', message.type === 'success' ? 'alert-success' : 'alert-error']"> <div
<Icon :icon="message.type === 'success' ? 'heroicons:check-circle' : 'heroicons:exclamation-circle'" class="w-6 h-6 shrink-0" /> v-if="message"
:class="[
'alert mb-6',
message.type === 'success' ? 'alert-success' : 'alert-error',
]"
>
<Icon
:icon="
message.type === 'success'
? 'heroicons:check-circle'
: 'heroicons:exclamation-circle'
"
class="w-6 h-6 shrink-0"
/>
<span>{{ message.text }}</span> <span>{{ message.text }}</span>
</div> </div>
@@ -73,11 +95,15 @@ async function changePassword() {
<form @submit.prevent="changePassword" class="space-y-5"> <form @submit.prevent="changePassword" class="space-y-5">
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label
<span class="label-text font-medium text-sm sm:text-base">Current Password</span> class="label pb-2 font-medium text-sm sm:text-base"
for="current-password"
>
Current Password
</label> </label>
<input <input
type="password" type="password"
id="current-password"
v-model="currentPassword" v-model="currentPassword"
placeholder="Enter current password" placeholder="Enter current password"
class="input input-bordered w-full" class="input input-bordered w-full"
@@ -86,11 +112,15 @@ async function changePassword() {
</div> </div>
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label
<span class="label-text font-medium text-sm sm:text-base">New Password</span> class="label pb-2 font-medium text-sm sm:text-base"
for="new-password"
>
New Password
</label> </label>
<input <input
type="password" type="password"
id="new-password"
v-model="newPassword" v-model="newPassword"
placeholder="Enter new password" placeholder="Enter new password"
class="input input-bordered w-full" class="input input-bordered w-full"
@@ -98,16 +128,23 @@ async function changePassword() {
minlength="8" minlength="8"
/> />
<div class="label pt-2"> <div class="label pt-2">
<span class="label-text-alt text-base-content/60 text-xs sm:text-sm">Minimum 8 characters</span> <span
class="label-text-alt text-base-content/60 text-xs sm:text-sm"
>Minimum 8 characters</span
>
</div> </div>
</div> </div>
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label
<span class="label-text font-medium text-sm sm:text-base">Confirm New Password</span> class="label pb-2 font-medium text-sm sm:text-base"
for="confirm-password"
>
Confirm New Password
</label> </label>
<input <input
type="password" type="password"
id="confirm-password"
v-model="confirmPassword" v-model="confirmPassword"
placeholder="Confirm new password" placeholder="Confirm new password"
class="input input-bordered w-full" class="input input-bordered w-full"
@@ -117,8 +154,15 @@ async function changePassword() {
</div> </div>
<div class="flex justify-end pt-4"> <div class="flex justify-end pt-4">
<button type="submit" class="btn btn-primary w-full sm:w-auto" :disabled="loading"> <button
<span v-if="loading" class="loading loading-spinner loading-sm"></span> type="submit"
class="btn btn-primary w-full sm:w-auto"
:disabled="loading"
>
<span
v-if="loading"
class="loading loading-spinner loading-sm"
></span>
<Icon v-else icon="heroicons:lock-closed" class="w-5 h-5" /> <Icon v-else icon="heroicons:lock-closed" class="w-5 h-5" />
Update Password Update Password
</button> </button>

View File

@@ -80,13 +80,15 @@ async function updateProfile() {
<form @submit.prevent="updateProfile" class="space-y-5"> <form @submit.prevent="updateProfile" class="space-y-5">
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label
<span class="label-text font-medium text-sm sm:text-base" class="label pb-2 font-medium text-sm sm:text-base"
>Full Name</span for="profile-name"
> >
Full Name
</label> </label>
<input <input
type="text" type="text"
id="profile-name"
v-model="name" v-model="name"
placeholder="Your full name" placeholder="Your full name"
class="input input-bordered w-full" class="input input-bordered w-full"
@@ -95,13 +97,15 @@ async function updateProfile() {
</div> </div>
<div class="form-control"> <div class="form-control">
<label class="label pb-2"> <label
<span class="label-text font-medium text-sm sm:text-base" class="label pb-2 font-medium text-sm sm:text-base"
>Email</span for="profile-email"
> >
Email
</label> </label>
<input <input
type="email" type="email"
id="profile-email"
:value="props.user.email" :value="props.user.email"
class="input input-bordered w-full" class="input input-bordered w-full"
disabled disabled

View File

@@ -33,6 +33,8 @@ export const organizations = sqliteTable("organizations", {
state: text("state"), state: text("state"),
zip: text("zip"), zip: text("zip"),
country: text("country"), country: text("country"),
defaultTaxRate: real("default_tax_rate").default(0),
defaultCurrency: text("default_currency").default("USD"),
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn( createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
() => new Date(), () => new Date(),
), ),
@@ -95,8 +97,8 @@ export const clients = sqliteTable(
}), }),
); );
export const categories = sqliteTable( export const tags = sqliteTable(
"categories", "tags",
{ {
id: text("id") id: text("id")
.primaryKey() .primaryKey()
@@ -104,6 +106,7 @@ export const categories = sqliteTable(
organizationId: text("organization_id").notNull(), organizationId: text("organization_id").notNull(),
name: text("name").notNull(), name: text("name").notNull(),
color: text("color"), color: text("color"),
rate: integer("rate").default(0),
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn( createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
() => new Date(), () => new Date(),
), ),
@@ -113,7 +116,7 @@ export const categories = sqliteTable(
columns: [table.organizationId], columns: [table.organizationId],
foreignColumns: [organizations.id], foreignColumns: [organizations.id],
}), }),
organizationIdIdx: index("categories_organization_id_idx").on( organizationIdIdx: index("tags_organization_id_idx").on(
table.organizationId, table.organizationId,
), ),
}), }),
@@ -128,10 +131,11 @@ export const timeEntries = sqliteTable(
userId: text("user_id").notNull(), userId: text("user_id").notNull(),
organizationId: text("organization_id").notNull(), organizationId: text("organization_id").notNull(),
clientId: text("client_id").notNull(), clientId: text("client_id").notNull(),
categoryId: text("category_id").notNull(), tagId: text("tag_id"),
startTime: integer("start_time", { mode: "timestamp" }).notNull(), startTime: integer("start_time", { mode: "timestamp" }).notNull(),
endTime: integer("end_time", { mode: "timestamp" }), endTime: integer("end_time", { mode: "timestamp" }),
description: text("description"), description: text("description"),
invoiceId: text("invoice_id"),
isManual: integer("is_manual", { mode: "boolean" }).default(false), isManual: integer("is_manual", { mode: "boolean" }).default(false),
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn( createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
() => new Date(), () => new Date(),
@@ -150,63 +154,18 @@ export const timeEntries = sqliteTable(
columns: [table.clientId], columns: [table.clientId],
foreignColumns: [clients.id], foreignColumns: [clients.id],
}), }),
categoryFk: foreignKey({ tagFk: foreignKey({
columns: [table.categoryId], columns: [table.tagId],
foreignColumns: [categories.id], foreignColumns: [tags.id],
}), }),
userIdIdx: index("time_entries_user_id_idx").on(table.userId), userIdIdx: index("time_entries_user_id_idx").on(table.userId),
organizationIdIdx: index("time_entries_organization_id_idx").on( organizationIdIdx: index("time_entries_organization_id_idx").on(
table.organizationId, table.organizationId,
), ),
clientIdIdx: index("time_entries_client_id_idx").on(table.clientId), clientIdIdx: index("time_entries_client_id_idx").on(table.clientId),
tagIdIdx: index("time_entries_tag_id_idx").on(table.tagId),
startTimeIdx: index("time_entries_start_time_idx").on(table.startTime), startTimeIdx: index("time_entries_start_time_idx").on(table.startTime),
}), invoiceIdIdx: index("time_entries_invoice_id_idx").on(table.invoiceId),
);
export const tags = sqliteTable(
"tags",
{
id: text("id")
.primaryKey()
.$defaultFn(() => nanoid()),
organizationId: text("organization_id").notNull(),
name: text("name").notNull(),
color: text("color"),
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
() => new Date(),
),
},
(table: any) => ({
orgFk: foreignKey({
columns: [table.organizationId],
foreignColumns: [organizations.id],
}),
organizationIdIdx: index("tags_organization_id_idx").on(
table.organizationId,
),
}),
);
export const timeEntryTags = sqliteTable(
"time_entry_tags",
{
timeEntryId: text("time_entry_id").notNull(),
tagId: text("tag_id").notNull(),
},
(table: any) => ({
pk: primaryKey({ columns: [table.timeEntryId, table.tagId] }),
timeEntryFk: foreignKey({
columns: [table.timeEntryId],
foreignColumns: [timeEntries.id],
}),
tagFk: foreignKey({
columns: [table.tagId],
foreignColumns: [tags.id],
}),
timeEntryIdIdx: index("time_entry_tags_time_entry_id_idx").on(
table.timeEntryId,
),
tagIdIdx: index("time_entry_tags_tag_id_idx").on(table.tagId),
}), }),
); );

View File

@@ -5,6 +5,7 @@ import { db } from '../db';
import { members, organizations } from '../db/schema'; import { members, organizations } from '../db/schema';
import { eq } from 'drizzle-orm'; import { eq } from 'drizzle-orm';
import Avatar from '../components/Avatar.astro'; import Avatar from '../components/Avatar.astro';
import ThemeToggle from '../components/ThemeToggle.vue';
import { ClientRouter } from "astro:transitions"; import { ClientRouter } from "astro:transitions";
interface Props { interface Props {
@@ -29,10 +30,24 @@ const userMemberships = await db.select({
const currentTeamId = Astro.cookies.get('currentTeamId')?.value || userMemberships[0]?.organization.id; const currentTeamId = Astro.cookies.get('currentTeamId')?.value || userMemberships[0]?.organization.id;
const currentTeam = userMemberships.find(m => m.organization.id === currentTeamId); const currentTeam = userMemberships.find(m => m.organization.id === currentTeamId);
const navItems = [
{ href: '/dashboard', label: 'Dashboard', icon: 'heroicons:home', exact: true },
{ href: '/dashboard/tracker', label: 'Time Tracker', icon: 'heroicons:clock' },
{ href: '/dashboard/invoices', label: 'Invoices & Quotes', icon: 'heroicons:document-currency-dollar' },
{ href: '/dashboard/reports', label: 'Reports', icon: 'heroicons:chart-bar' },
{ href: '/dashboard/clients', label: 'Clients', icon: 'heroicons:building-office' },
{ href: '/dashboard/team', label: 'Team', icon: 'heroicons:user-group' },
];
function isActive(item: { href: string; exact?: boolean }) {
if (item.exact) return Astro.url.pathname === item.href;
return Astro.url.pathname.startsWith(item.href);
}
--- ---
<!doctype html> <!doctype html>
<html lang="en" data-theme="dark"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="description" content="Chronus Dashboard" /> <meta name="description" content="Chronus Dashboard" />
@@ -41,152 +56,146 @@ const currentTeam = userMemberships.find(m => m.organization.id === currentTeamI
<meta name="generator" content={Astro.generator} /> <meta name="generator" content={Astro.generator} />
<title>{title}</title> <title>{title}</title>
<ClientRouter /> <ClientRouter />
<script is:inline>
const theme = localStorage.getItem('theme') || 'macchiato';
document.documentElement.setAttribute('data-theme', theme);
</script>
</head> </head>
<body class="bg-base-100 h-screen flex flex-col overflow-hidden"> <body class="bg-base-100 h-screen flex flex-col overflow-hidden">
<div class="drawer lg:drawer-open flex-1 overflow-auto"> <div class="drawer lg:drawer-open flex-1 overflow-auto">
<input id="my-drawer-2" type="checkbox" class="drawer-toggle" /> <input id="my-drawer-2" type="checkbox" class="drawer-toggle" />
<div class="drawer-content flex flex-col h-full overflow-auto"> <div class="drawer-content flex flex-col h-full overflow-auto">
<!-- Navbar --> <!-- Mobile Navbar -->
<div class="navbar bg-base-200/50 backdrop-blur-sm sticky top-0 z-50 lg:hidden border-b border-base-300/50"> <div class="navbar bg-base-100 sticky top-0 z-50 lg:hidden border-b border-base-200">
<div class="flex-none lg:hidden"> <div class="flex-none">
<label for="my-drawer-2" aria-label="open sidebar" class="btn btn-square btn-ghost"> <label for="my-drawer-2" aria-label="open sidebar" class="btn btn-square btn-ghost btn-sm">
<Icon name="heroicons:bars-3" class="w-6 h-6" /> <Icon name="heroicons:bars-3" class="w-5 h-5" />
</label> </label>
</div> </div>
<div class="flex-1 px-2 flex items-center gap-2"> <div class="flex-1 px-2 flex items-center gap-2">
<img src="/logo.webp" alt="Chronus" class="h-8 w-8" /> <img src="/logo.webp" alt="Chronus" class="h-7 w-7" />
<span class="text-xl font-bold text-primary">Chronus</span> <span class="text-lg font-bold text-primary">Chronus</span>
</div>
<div class="flex-none">
<ThemeToggle client:load />
</div> </div>
</div> </div>
<!-- Page content here --> <!-- Page content -->
<main class="p-6 md:p-8"> <main class="flex-1 p-4 sm:p-6 lg:p-8">
<slot /> <slot />
</main> </main>
</div> </div>
<div class="drawer-side z-50"> <div class="drawer-side z-50">
<label for="my-drawer-2" aria-label="close sidebar" class="drawer-overlay"></label> <label for="my-drawer-2" aria-label="close sidebar" class="drawer-overlay"></label>
<ul class="menu bg-base-200/95 backdrop-blur-sm min-h-full w-80 p-4 border-r border-base-300/30"> <aside class="bg-base-200 min-h-full w-72 flex flex-col border-r border-base-300/40">
<!-- Sidebar content here --> <!-- Logo -->
<li class="mb-6"> <div class="px-5 pt-5 pb-3">
<a href="/dashboard" class="flex items-center gap-3 text-2xl font-bold text-primary hover:bg-transparent"> <a href="/dashboard" class="flex items-center gap-2.5 group">
<img src="/logo.webp" alt="Chronus" class="h-10 w-10" /> <img src="/logo.webp" alt="Chronus" class="h-8 w-8" />
Chronus <span class="text-xl font-bold text-primary">Chronus</span>
</a> </a>
</li> </div>
{/* Team Switcher */} <!-- Team Switcher -->
{userMemberships.length > 0 && ( {userMemberships.length > 0 && (
<li class="mb-4"> <div class="px-4 pb-2">
<div class="form-control"> <select
<select class="select select-sm w-full bg-base-300/40 border-base-300/60 focus:border-primary/50 focus:outline-none text-sm font-medium"
class="select select-bordered w-full font-semibold bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary focus:outline-none focus:outline-offset-0 transition-all duration-200 hover:border-primary/40 focus:ring-3 focus:ring-primary/15 [&>option]:bg-base-300 [&>option]:text-base-content [&>option]:p-2" id="team-switcher"
id="team-switcher" aria-label="Switch team"
onchange="document.cookie = 'currentTeamId=' + this.value + '; path=/'; window.location.reload();" onchange="document.cookie = 'currentTeamId=' + this.value + '; path=/'; window.location.reload();"
> >
{userMemberships.map(({ membership, organization }) => ( {userMemberships.map(({ membership, organization }) => (
<option <option
value={organization.id} value={organization.id}
selected={organization.id === currentTeamId} selected={organization.id === currentTeamId}
> >
{organization.name} {organization.name}
</option> </option>
))} ))}
</select> </select>
</div> </div>
</li>
)} )}
{userMemberships.length === 0 && ( {userMemberships.length === 0 && (
<li class="mb-4"> <div class="px-4 pb-2">
<a href="/dashboard/organizations/new" class="btn btn-primary btn-sm"> <a href="/dashboard/organizations/new" class="btn btn-primary btn-sm btn-block">
<Icon name="heroicons:plus" class="w-4 h-4" /> <Icon name="heroicons:plus" class="w-4 h-4" />
Create Team Create Team
</a> </a>
</li> </div>
)} )}
<div class="divider my-2"></div> <div class="divider my-1 mx-4"></div>
<li><a href="/dashboard" class:list={[ <!-- Navigation -->
"hover:bg-base-300/50 rounded-lg transition-colors active:bg-base-300/50!", <nav class="flex-1 px-3">
{ "bg-primary/10 text-primary relative before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:w-0.75 before:h-[70%] before:bg-primary before:rounded-r-full": Astro.url.pathname === "/dashboard" } <ul class="menu menu-sm gap-0.5 p-0">
]}> {navItems.map(item => (
<Icon name="heroicons:home" class="w-5 h-5" /> <li>
Dashboard <a href={item.href} class:list={[
</a></li> "rounded-lg gap-3 px-3 py-2.5 font-medium text-sm",
<li><a href="/dashboard/tracker" class:list={[ isActive(item)
"hover:bg-base-300/50 rounded-lg transition-colors active:bg-base-300/50!", ? "bg-primary/10 text-primary"
{ "bg-primary/10 text-primary relative before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:w-0.75 before:h-[70%] before:bg-primary before:rounded-r-full": Astro.url.pathname.startsWith("/dashboard/tracker") } : "text-base-content/70 hover:text-base-content hover:bg-base-300/50"
]}> ]}>
<Icon name="heroicons:clock" class="w-5 h-5" /> <Icon name={item.icon} class="w-[18px] h-[18px]" />
Time Tracker {item.label}
</a></li> </a>
<li><a href="/dashboard/invoices" class:list={[ </li>
"hover:bg-base-300/50 rounded-lg transition-colors active:bg-base-300/50!", ))}
{ "bg-primary/10 text-primary relative before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:w-0.75 before:h-[70%] before:bg-primary before:rounded-r-full": Astro.url.pathname.startsWith("/dashboard/invoices") } </ul>
]}>
<Icon name="heroicons:document-currency-dollar" class="w-5 h-5" />
Invoices & Quotes
</a></li>
<li><a href="/dashboard/reports" class:list={[
"hover:bg-base-300/50 rounded-lg transition-colors active:bg-base-300/50!",
{ "bg-primary/10 text-primary relative before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:w-0.75 before:h-[70%] before:bg-primary before:rounded-r-full": Astro.url.pathname.startsWith("/dashboard/reports") }
]}>
<Icon name="heroicons:chart-bar" class="w-5 h-5" />
Reports
</a></li>
<li><a href="/dashboard/clients" class:list={[
"hover:bg-base-300/50 rounded-lg transition-colors active:bg-base-300/50!",
{ "bg-primary/10 text-primary relative before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:w-0.75 before:h-[70%] before:bg-primary before:rounded-r-full": Astro.url.pathname.startsWith("/dashboard/clients") }
]}>
<Icon name="heroicons:building-office" class="w-5 h-5" />
Clients
</a></li>
<li><a href="/dashboard/team" class:list={[
"hover:bg-base-300/50 rounded-lg transition-colors active:bg-base-300/50!",
{ "bg-primary/10 text-primary relative before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:w-0.75 before:h-[70%] before:bg-primary before:rounded-r-full": Astro.url.pathname.startsWith("/dashboard/team") }
]}>
<Icon name="heroicons:user-group" class="w-5 h-5" />
Team
</a></li>
{user.isSiteAdmin && ( {user.isSiteAdmin && (
<> <>
<div class="divider my-2"></div> <div class="divider my-1"></div>
<li><a href="/admin" class:list={[ <ul class="menu menu-sm p-0">
"font-semibold hover:bg-base-300/50 rounded-lg transition-colors active:bg-base-300/50!", <li>
{ "bg-primary/10 text-primary relative before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:w-0.75 before:h-[70%] before:bg-primary before:rounded-r-full": Astro.url.pathname.startsWith("/admin") } <a href="/admin" class:list={[
]}> "rounded-lg gap-3 px-3 py-2.5 font-medium text-sm",
<Icon name="heroicons:cog-6-tooth" class="w-5 h-5" /> Astro.url.pathname.startsWith("/admin")
Site Admin ? "bg-primary/10 text-primary"
</a></li> : "text-base-content/70 hover:text-base-content hover:bg-base-300/50"
</> ]}>
)} <Icon name="heroicons:cog-6-tooth" class="w-[18px] h-[18px]" />
Site Admin
</a>
</li>
</ul>
</>
)}
</nav>
<div class="divider my-2"></div> <!-- Bottom Section -->
<div class="mt-auto border-t border-base-300/40">
<div class="p-3">
<a href="/dashboard/settings" class="flex items-center gap-3 rounded-lg p-2.5 hover:bg-base-300/40 group">
<Avatar name={user.name} />
<div class="flex-1 min-w-0">
<div class="font-medium text-sm truncate">{user.name}</div>
<div class="text-xs text-base-content/50 truncate">{user.email}</div>
</div>
<Icon name="heroicons:chevron-right" class="w-4 h-4 text-base-content/30 group-hover:text-base-content/50" />
</a>
</div>
<li> <div class="flex items-center justify-between px-5 pb-2">
<a href="/dashboard/settings" class="flex items-center gap-3 bg-base-300/30 hover:bg-base-300/60 rounded-lg p-3 transition-colors"> <span class="text-xs text-base-content/40 font-medium">Theme</span>
<Avatar name={user.name} /> <ThemeToggle client:load />
<div class="flex-1 min-w-0"> </div>
<div class="font-semibold text-sm truncate">{user.name}</div>
<div class="text-xs text-base-content/50 truncate">{user.email}</div>
</div>
<Icon name="heroicons:chevron-right" class="w-4 h-4 opacity-40" />
</a>
</li>
<li>
<form action="/api/auth/logout" method="POST" class="contents">
<button type="submit" class="flex w-full items-center gap-2 py-2 px-4 text-error hover:bg-error/10 rounded-lg transition-colors active:bg-base-300/50!">
<Icon name="heroicons:arrow-right-on-rectangle" class="w-5 h-5" />
Logout
</button>
</form>
</li>
</ul>
<div class="px-3 pb-3">
<form action="/api/auth/logout" method="POST">
<button type="submit" class="btn btn-ghost btn-sm btn-block justify-start gap-2 text-base-content/60 hover:text-error hover:bg-error/10 font-medium">
<Icon name="heroicons:arrow-right-on-rectangle" class="w-[18px] h-[18px]" />
Logout
</button>
</form>
</div>
</div>
</aside>
</div> </div>
</div> </div>
</body> </body>

View File

@@ -10,7 +10,7 @@ const { title } = Astro.props;
--- ---
<!doctype html> <!doctype html>
<html lang="en" data-theme="dark"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="description" content="Chronus Time Tracking" /> <meta name="description" content="Chronus Time Tracking" />
@@ -19,6 +19,10 @@ const { title } = Astro.props;
<meta name="generator" content={Astro.generator} /> <meta name="generator" content={Astro.generator} />
<title>{title}</title> <title>{title}</title>
<ClientRouter /> <ClientRouter />
<script is:inline>
const theme = localStorage.getItem('theme') || 'macchiato';
document.documentElement.setAttribute('data-theme', theme);
</script>
</head> </head>
<body class="min-h-screen bg-base-100 text-base-content flex flex-col"> <body class="min-h-screen bg-base-100 text-base-content flex flex-col">
<div class="flex-1 flex flex-col"> <div class="flex-1 flex flex-col">

View File

@@ -25,3 +25,16 @@ export function formatTimeRange(start: Date, end: Date | null): string {
const ms = end.getTime() - start.getTime(); const ms = end.getTime() - start.getTime();
return formatDuration(ms); return formatDuration(ms);
} }
/**
* Formats a cent-based amount as a currency string.
* @param amount - Amount in cents (e.g. 1500 = $15.00)
* @param currency - ISO 4217 currency code (default: 'USD')
* @returns Formatted currency string like "$15.00"
*/
export function formatCurrency(amount: number, currency: string = "USD"): string {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: currency,
}).format(amount / 100);
}

24
src/lib/getCurrentTeam.ts Normal file
View File

@@ -0,0 +1,24 @@
import { db } from '../db';
import { members } from '../db/schema';
import { eq } from 'drizzle-orm';
type User = { id: string; [key: string]: any };
/**
* Get the current team membership for a user based on the currentTeamId cookie.
* Returns the membership row, or null if the user has no memberships.
*/
export async function getCurrentTeam(user: User, currentTeamId?: string | null) {
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return null;
const membership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
return membership;
}

View File

@@ -1,63 +1,66 @@
import { db } from "../db"; import { db } from "../db";
import { clients, categories, tags as tagsTable } from "../db/schema"; import { clients, tags as tagsTable } from "../db/schema";
import { eq, and, inArray } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
export const MAX_LENGTHS = {
name: 255,
email: 320,
password: 128,
phone: 50,
address: 255, // street, city, state, zip, country
currency: 10,
invoiceNumber: 50,
invoiceNotes: 5000,
itemDescription: 2000,
description: 2000, // time entry description
} as const;
export function exceedsLength(
field: string,
value: string | null | undefined,
maxLength: number,
): string | null {
if (value && value.length > maxLength) {
return `${field} must be ${maxLength} characters or fewer`;
}
return null;
}
export async function validateTimeEntryResources({ export async function validateTimeEntryResources({
organizationId, organizationId,
clientId, clientId,
categoryId, tagId,
tagIds,
}: { }: {
organizationId: string; organizationId: string;
clientId: string; clientId: string;
categoryId: string; tagId?: string | null;
tagIds?: string[];
}) { }) {
const [client, category] = await Promise.all([ const client = await db
db .select()
.select() .from(clients)
.from(clients) .where(
.where( and(eq(clients.id, clientId), eq(clients.organizationId, organizationId)),
and( )
eq(clients.id, clientId), .get();
eq(clients.organizationId, organizationId),
),
)
.get(),
db
.select()
.from(categories)
.where(
and(
eq(categories.id, categoryId),
eq(categories.organizationId, organizationId),
),
)
.get(),
]);
if (!client) { if (!client) {
return { valid: false, error: "Invalid client" }; return { valid: false, error: "Invalid client" };
} }
if (!category) { if (tagId) {
return { valid: false, error: "Invalid category" }; const validTag = await db
}
if (tagIds && tagIds.length > 0) {
const validTags = await db
.select() .select()
.from(tagsTable) .from(tagsTable)
.where( .where(
and( and(
inArray(tagsTable.id, tagIds), eq(tagsTable.id, tagId),
eq(tagsTable.organizationId, organizationId), eq(tagsTable.organizationId, organizationId),
), ),
) )
.all(); .get();
if (validTags.length !== tagIds.length) { if (!validTag) {
return { valid: false, error: "Invalid tags" }; return { valid: false, error: "Invalid tag" };
} }
} }
@@ -81,3 +84,9 @@ export function validateTimeRange(
return { valid: true, startDate, endDate }; return { valid: true, startDate, endDate };
} }
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
export function isValidEmail(email: string): boolean {
return EMAIL_REGEX.test(email) && email.length <= 320;
}

View File

@@ -1,6 +1,7 @@
--- ---
import DashboardLayout from '../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../layouts/DashboardLayout.astro';
import Avatar from '../../components/Avatar.astro'; import Avatar from '../../components/Avatar.astro';
import StatCard from '../../components/StatCard.astro';
import { db } from '../../db'; import { db } from '../../db';
import { siteSettings, users } from '../../db/schema'; import { siteSettings, users } from '../../db/schema';
import { eq } from 'drizzle-orm'; import { eq } from 'drizzle-orm';
@@ -21,52 +22,52 @@ const allUsers = await db.select().from(users).all();
--- ---
<DashboardLayout title="Site Admin - Chronus"> <DashboardLayout title="Site Admin - Chronus">
<h1 class="text-3xl font-bold mb-6">Site Administration</h1> <div class="mb-6">
<h1 class="text-2xl font-extrabold tracking-tight">Site Administration</h1>
<p class="text-base-content/60 text-sm mt-1">Manage users and site settings</p>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6"> <div class="grid grid-cols-1 sm:grid-cols-2 gap-3 mb-6">
<!-- Statistics --> <StatCard
<div class="stats shadow border border-base-200"> title="Total Users"
<div class="stat"> value={String(allUsers.length)}
<div class="stat-title">Total Users</div> description="Registered accounts"
<div class="stat-value">{allUsers.length}</div> icon="heroicons:users"
</div> color="text-primary"
</div> />
</div> </div>
<!-- Settings --> <!-- Settings -->
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4">Site Settings</h2> <h2 class="text-sm font-semibold flex items-center gap-2 mb-4">Site Settings</h2>
<form method="POST" action="/api/admin/settings"> <form method="POST" action="/api/admin/settings">
<div class="form-control"> <fieldset class="fieldset">
<label class="label cursor-pointer"> <legend class="fieldset-legend text-xs">Allow New Registrations</legend>
<span class="label-text flex-1 min-w-0 pr-4"> <input
<div class="font-semibold">Allow New Registrations</div> type="checkbox"
<div class="text-sm text-gray-500">When disabled, only existing users can log in</div> name="registration_enabled"
</span> class="toggle toggle-primary shrink-0"
<input checked={registrationEnabled}
type="checkbox" />
name="registration_enabled" </fieldset>
class="toggle toggle-primary"
checked={registrationEnabled}
/>
</label>
</div>
<div class="card-actions justify-end mt-6"> <div class="flex justify-end mt-4">
<button type="submit" class="btn btn-primary">Save Settings</button> <button type="submit" class="btn btn-primary btn-sm">Save Settings</button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
<!-- Users List --> <!-- Users List -->
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-0">
<h2 class="card-title mb-4">All Users</h2> <div class="px-4 py-3 border-b border-base-200">
<h2 class="text-sm font-semibold">All Users</h2>
</div>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@@ -77,22 +78,22 @@ const allUsers = await db.select().from(users).all();
</thead> </thead>
<tbody> <tbody>
{allUsers.map(u => ( {allUsers.map(u => (
<tr> <tr class="hover">
<td> <td>
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<Avatar name={u.name} /> <Avatar name={u.name} />
<div class="font-bold">{u.name}</div> <div class="font-medium">{u.name}</div>
</div> </div>
</td> </td>
<td>{u.email}</td> <td class="text-base-content/60">{u.email}</td>
<td> <td>
{u.isSiteAdmin ? ( {u.isSiteAdmin ? (
<span class="badge badge-primary">Yes</span> <span class="badge badge-xs badge-primary">Yes</span>
) : ( ) : (
<span class="badge badge-ghost">No</span> <span class="badge badge-xs badge-ghost">No</span>
)} )}
</td> </td>
<td>{u.createdAt?.toLocaleDateString() ?? 'N/A'}</td> <td class="text-base-content/40">{u.createdAt?.toLocaleDateString() ?? 'N/A'}</td>
</tr> </tr>
))} ))}
</tbody> </tbody>

View File

@@ -65,7 +65,8 @@ export const POST: APIRoute = async ({ request, cookies }) => {
}, },
}); });
} catch (error) { } catch (error) {
return new Response(JSON.stringify({ error: (error as Error).message }), { console.error("Passkey authentication verification failed:", error);
return new Response(JSON.stringify({ error: "Verification failed" }), {
status: 400, status: 400,
}); });
} }

View File

@@ -2,8 +2,13 @@ import type { APIRoute } from "astro";
import { generateAuthenticationOptions } from "@simplewebauthn/server"; import { generateAuthenticationOptions } from "@simplewebauthn/server";
import { db } from "../../../../../db"; import { db } from "../../../../../db";
import { passkeyChallenges } from "../../../../../db/schema"; import { passkeyChallenges } from "../../../../../db/schema";
import { lte } from "drizzle-orm";
export const GET: APIRoute = async ({ request }) => { export const GET: APIRoute = async ({ request }) => {
await db
.delete(passkeyChallenges)
.where(lte(passkeyChallenges.expiresAt, new Date()));
const options = await generateAuthenticationOptions({ const options = await generateAuthenticationOptions({
rpID: new URL(request.url).hostname, rpID: new URL(request.url).hostname,
userVerification: "preferred", userVerification: "preferred",

View File

@@ -48,7 +48,8 @@ export const POST: APIRoute = async ({ request, locals }) => {
expectedRPID: new URL(request.url).hostname, expectedRPID: new URL(request.url).hostname,
}); });
} catch (error) { } catch (error) {
return new Response(JSON.stringify({ error: (error as Error).message }), { console.error("Passkey registration verification failed:", error);
return new Response(JSON.stringify({ error: "Verification failed" }), {
status: 400, status: 400,
}); });
} }

View File

@@ -2,7 +2,7 @@ import type { APIRoute } from "astro";
import { generateRegistrationOptions } from "@simplewebauthn/server"; import { generateRegistrationOptions } from "@simplewebauthn/server";
import { db } from "../../../../../db"; import { db } from "../../../../../db";
import { passkeys, passkeyChallenges } from "../../../../../db/schema"; import { passkeys, passkeyChallenges } from "../../../../../db/schema";
import { eq } from "drizzle-orm"; import { eq, lte } from "drizzle-orm";
export const GET: APIRoute = async ({ request, locals }) => { export const GET: APIRoute = async ({ request, locals }) => {
const user = locals.user; const user = locals.user;
@@ -13,6 +13,10 @@ export const GET: APIRoute = async ({ request, locals }) => {
}); });
} }
await db
.delete(passkeyChallenges)
.where(lte(passkeyChallenges.expiresAt, new Date()));
const userPasskeys = await db.query.passkeys.findMany({ const userPasskeys = await db.query.passkeys.findMany({
where: eq(passkeys.userId, user.id), where: eq(passkeys.userId, user.id),
}); });

View File

@@ -7,6 +7,7 @@ import {
siteSettings, siteSettings,
} from "../../../db/schema"; } from "../../../db/schema";
import { hashPassword, createSession } from "../../../lib/auth"; import { hashPassword, createSession } from "../../../lib/auth";
import { isValidEmail, MAX_LENGTHS } from "../../../lib/validation";
import { eq, count, sql } from "drizzle-orm"; import { eq, count, sql } from "drizzle-orm";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
@@ -37,6 +38,18 @@ export const POST: APIRoute = async ({ request, cookies, redirect }) => {
return redirect("/signup?error=missing_fields"); return redirect("/signup?error=missing_fields");
} }
if (!isValidEmail(email)) {
return redirect("/signup?error=invalid_email");
}
if (name.length > MAX_LENGTHS.name) {
return redirect("/signup?error=name_too_long");
}
if (password.length > MAX_LENGTHS.password) {
return redirect("/signup?error=password_too_long");
}
if (password.length < 8) { if (password.length < 8) {
return redirect("/signup?error=password_too_short"); return redirect("/signup?error=password_too_short");
} }
@@ -47,7 +60,7 @@ export const POST: APIRoute = async ({ request, cookies, redirect }) => {
.where(eq(users.email, email)) .where(eq(users.email, email))
.get(); .get();
if (existingUser) { if (existingUser) {
return redirect("/signup?error=user_exists"); return redirect("/login?registered=true");
} }
const passwordHash = await hashPassword(password); const passwordHash = await hashPassword(password);

View File

@@ -1,67 +0,0 @@
import type { APIRoute } from "astro";
import { db } from "../../../../db";
import { categories, members, timeEntries } from "../../../../db/schema";
import { eq, and } from "drizzle-orm";
export const POST: APIRoute = async ({ request, locals, redirect, params }) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
const { id } = params;
let redirectTo: string | undefined;
if (request.headers.get("Content-Type")?.includes("application/json")) {
const body = await request.json();
redirectTo = body.redirectTo;
} else {
const formData = await request.formData();
redirectTo = formData.get("redirectTo")?.toString();
}
const userOrg = await db
.select()
.from(members)
.where(eq(members.userId, user.id))
.get();
if (!userOrg) {
return new Response("No organization found", { status: 400 });
}
const isAdmin = userOrg.role === "owner" || userOrg.role === "admin";
if (!isAdmin) {
return new Response("Forbidden", { status: 403 });
}
const hasEntries = await db
.select()
.from(timeEntries)
.where(eq(timeEntries.categoryId, id!))
.get();
if (hasEntries) {
return new Response("Cannot delete category with time entries", {
status: 400,
});
}
await db
.delete(categories)
.where(
and(
eq(categories.id, id!),
eq(categories.organizationId, userOrg.organizationId),
),
);
if (locals.scopes) {
return new Response(JSON.stringify({ success: true }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
return redirect(redirectTo || "/dashboard/team/settings");
};

View File

@@ -1,72 +0,0 @@
import type { APIRoute } from "astro";
import { db } from "../../../../db";
import { categories, members } from "../../../../db/schema";
import { eq, and } from "drizzle-orm";
export const POST: APIRoute = async ({ request, locals, redirect, params }) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
const { id } = params;
let name: string | undefined;
let color: string | undefined;
let redirectTo: string | undefined;
if (request.headers.get("Content-Type")?.includes("application/json")) {
const body = await request.json();
name = body.name;
color = body.color;
redirectTo = body.redirectTo;
} else {
const formData = await request.formData();
name = formData.get("name")?.toString();
color = formData.get("color")?.toString();
redirectTo = formData.get("redirectTo")?.toString();
}
if (!name) {
return new Response("Name is required", { status: 400 });
}
const userOrg = await db
.select()
.from(members)
.where(eq(members.userId, user.id))
.get();
if (!userOrg) {
return new Response("No organization found", { status: 400 });
}
const isAdmin = userOrg.role === "owner" || userOrg.role === "admin";
if (!isAdmin) {
return new Response("Forbidden", { status: 403 });
}
await db
.update(categories)
.set({
name,
color: color || null,
})
.where(
and(
eq(categories.id, id!),
eq(categories.organizationId, userOrg.organizationId),
),
);
if (locals.scopes) {
return new Response(
JSON.stringify({ success: true, id, name, color: color || null }),
{
status: 200,
headers: { "Content-Type": "application/json" },
},
);
}
return redirect(redirectTo || "/dashboard/team/settings");
};

View File

@@ -1,59 +0,0 @@
import type { APIRoute } from "astro";
import { db } from "../../../db";
import { categories, members } from "../../../db/schema";
import { eq } from "drizzle-orm";
import { nanoid } from "nanoid";
export const POST: APIRoute = async ({ request, locals, redirect }) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
let name: string | undefined;
let color: string | undefined;
let redirectTo: string | undefined;
if (request.headers.get("Content-Type")?.includes("application/json")) {
const body = await request.json();
name = body.name;
color = body.color;
redirectTo = body.redirectTo;
} else {
const formData = await request.formData();
name = formData.get("name")?.toString();
color = formData.get("color")?.toString();
redirectTo = formData.get("redirectTo")?.toString();
}
if (!name) {
return new Response("Name is required", { status: 400 });
}
const userOrg = await db
.select()
.from(members)
.where(eq(members.userId, user.id))
.get();
if (!userOrg) {
return new Response("No organization found", { status: 400 });
}
const id = nanoid();
await db.insert(categories).values({
id,
organizationId: userOrg.organizationId,
name,
color: color || null,
});
if (locals.scopes) {
return new Response(JSON.stringify({ id, name, color: color || null }), {
status: 201,
headers: { "Content-Type": "application/json" },
});
}
return redirect(redirectTo || "/dashboard/team/settings");
};

View File

@@ -1,12 +1,7 @@
import type { APIRoute } from "astro"; import type { APIRoute } from "astro";
import { db } from "../../../../db"; import { db } from "../../../../db";
import { import { clients, members, timeEntries } from "../../../../db/schema";
clients, import { eq, and } from "drizzle-orm";
members,
timeEntries,
timeEntryTags,
} from "../../../../db/schema";
import { eq, and, inArray } from "drizzle-orm";
export const POST: APIRoute = async ({ params, locals, redirect }) => { export const POST: APIRoute = async ({ params, locals, redirect }) => {
const user = locals.user; const user = locals.user;
@@ -57,23 +52,19 @@ export const POST: APIRoute = async ({ params, locals, redirect }) => {
return new Response("Not authorized", { status: 403 }); return new Response("Not authorized", { status: 403 });
} }
const clientEntries = await db const isAdminOrOwner = membership.role === "owner" || membership.role === "admin";
.select({ id: timeEntries.id }) if (!isAdminOrOwner) {
.from(timeEntries) if (locals.scopes) {
.where(eq(timeEntries.clientId, id)) return new Response(
.all(); JSON.stringify({ error: "Only owners and admins can delete clients" }),
{ status: 403, headers: { "Content-Type": "application/json" } },
const entryIds = clientEntries.map((e) => e.id); );
}
if (entryIds.length > 0) { return new Response("Only owners and admins can delete clients", { status: 403 });
await db
.delete(timeEntryTags)
.where(inArray(timeEntryTags.timeEntryId, entryIds))
.run();
await db.delete(timeEntries).where(eq(timeEntries.clientId, id)).run();
} }
await db.delete(timeEntries).where(eq(timeEntries.clientId, id)).run();
await db.delete(clients).where(eq(clients.id, id)).run(); await db.delete(clients).where(eq(clients.id, id)).run();
if (locals.scopes) { if (locals.scopes) {

View File

@@ -2,6 +2,7 @@ import type { APIRoute } from "astro";
import { db } from "../../../../db"; import { db } from "../../../../db";
import { clients, members } from "../../../../db/schema"; import { clients, members } from "../../../../db/schema";
import { eq, and } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
import { MAX_LENGTHS, exceedsLength } from "../../../../lib/validation";
export const POST: APIRoute = async ({ request, params, locals, redirect }) => { export const POST: APIRoute = async ({ request, params, locals, redirect }) => {
const user = locals.user; const user = locals.user;
@@ -49,6 +50,25 @@ export const POST: APIRoute = async ({ request, params, locals, redirect }) => {
return new Response("Client name is required", { status: 400 }); return new Response("Client name is required", { status: 400 });
} }
const lengthError =
exceedsLength("Name", name, MAX_LENGTHS.name) ||
exceedsLength("Email", email, MAX_LENGTHS.email) ||
exceedsLength("Phone", phone, MAX_LENGTHS.phone) ||
exceedsLength("Street", street, MAX_LENGTHS.address) ||
exceedsLength("City", city, MAX_LENGTHS.address) ||
exceedsLength("State", state, MAX_LENGTHS.address) ||
exceedsLength("ZIP", zip, MAX_LENGTHS.address) ||
exceedsLength("Country", country, MAX_LENGTHS.address);
if (lengthError) {
if (locals.scopes) {
return new Response(JSON.stringify({ error: lengthError }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
return new Response(lengthError, { status: 400 });
}
try { try {
const client = await db const client = await db
.select() .select()
@@ -87,6 +107,17 @@ export const POST: APIRoute = async ({ request, params, locals, redirect }) => {
return new Response("Not authorized", { status: 403 }); return new Response("Not authorized", { status: 403 });
} }
const isAdminOrOwner = membership.role === "owner" || membership.role === "admin";
if (!isAdminOrOwner) {
if (locals.scopes) {
return new Response(
JSON.stringify({ error: "Only owners and admins can update clients" }),
{ status: 403, headers: { "Content-Type": "application/json" } },
);
}
return new Response("Only owners and admins can update clients", { status: 403 });
}
await db await db
.update(clients) .update(clients)
.set({ .set({

View File

@@ -3,6 +3,7 @@ import { db } from "../../../db";
import { clients, members } from "../../../db/schema"; import { clients, members } from "../../../db/schema";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
import { MAX_LENGTHS, exceedsLength } from "../../../lib/validation";
export const POST: APIRoute = async ({ request, locals, redirect }) => { export const POST: APIRoute = async ({ request, locals, redirect }) => {
const user = locals.user; const user = locals.user;
@@ -45,6 +46,25 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
return new Response("Name is required", { status: 400 }); return new Response("Name is required", { status: 400 });
} }
const lengthError =
exceedsLength("Name", name, MAX_LENGTHS.name) ||
exceedsLength("Email", email, MAX_LENGTHS.email) ||
exceedsLength("Phone", phone, MAX_LENGTHS.phone) ||
exceedsLength("Street", street, MAX_LENGTHS.address) ||
exceedsLength("City", city, MAX_LENGTHS.address) ||
exceedsLength("State", state, MAX_LENGTHS.address) ||
exceedsLength("ZIP", zip, MAX_LENGTHS.address) ||
exceedsLength("Country", country, MAX_LENGTHS.address);
if (lengthError) {
if (locals.scopes) {
return new Response(JSON.stringify({ error: lengthError }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
return new Response(lengthError, { status: 400 });
}
const userOrg = await db const userOrg = await db
.select() .select()
.from(members) .from(members)
@@ -55,6 +75,17 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
return new Response("No organization found", { status: 400 }); return new Response("No organization found", { status: 400 });
} }
const isAdminOrOwner = userOrg.role === "owner" || userOrg.role === "admin";
if (!isAdminOrOwner) {
if (locals.scopes) {
return new Response(
JSON.stringify({ error: "Only owners and admins can create clients" }),
{ status: 403, headers: { "Content-Type": "application/json" } },
);
}
return new Response("Only owners and admins can create clients", { status: 403 });
}
const id = nanoid(); const id = nanoid();
await db.insert(clients).values({ await db.insert(clients).values({

View File

@@ -45,6 +45,11 @@ export const POST: APIRoute = async ({ redirect, locals, params }) => {
return new Response("Unauthorized", { status: 401 }); return new Response("Unauthorized", { status: 401 });
} }
const isAdminOrOwner = membership.role === "owner" || membership.role === "admin";
if (!isAdminOrOwner) {
return new Response("Only owners and admins can convert quotes", { status: 403 });
}
try { try {
const lastInvoice = await db const lastInvoice = await db
.select() .select()

View File

@@ -1,4 +1,5 @@
import type { APIRoute } from "astro"; import type { APIRoute } from "astro";
import { renderToStream } from "@ceereals/vue-pdf";
import { db } from "../../../../db"; import { db } from "../../../../db";
import { import {
invoices, invoices,
@@ -8,95 +9,109 @@ import {
members, members,
} from "../../../../db/schema"; } from "../../../../db/schema";
import { eq, and } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
import { renderToStream } from "@ceereals/vue-pdf";
import { createInvoiceDocument } from "../../../../pdf/generateInvoicePDF"; import { createInvoiceDocument } from "../../../../pdf/generateInvoicePDF";
export const GET: APIRoute = async ({ params, locals }) => { export const GET: APIRoute = async ({ params, locals }) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
const { id } = params;
if (!id) {
return new Response("Invoice ID is required", { status: 400 });
}
// Fetch invoice with related data
const invoiceResult = await db
.select({
invoice: invoices,
client: clients,
organization: organizations,
})
.from(invoices)
.leftJoin(clients, eq(invoices.clientId, clients.id))
.innerJoin(organizations, eq(invoices.organizationId, organizations.id))
.where(eq(invoices.id, id))
.get();
if (!invoiceResult) {
return new Response("Invoice not found", { status: 404 });
}
const { invoice, client, organization } = invoiceResult;
// Verify membership
const membership = await db
.select()
.from(members)
.where(
and(
eq(members.userId, user.id),
eq(members.organizationId, invoice.organizationId),
),
)
.get();
if (!membership) {
return new Response("Not authorized", { status: 403 });
}
// Fetch items
const items = await db
.select()
.from(invoiceItems)
.where(eq(invoiceItems.invoiceId, invoice.id))
.all();
try { try {
const { id } = params; const document = createInvoiceDocument({
const user = locals.user; invoice: {
...invoice,
notes: invoice.notes || null,
// Ensure null safety for optional fields that might be undefined in some runtimes depending on driver
discountValue: invoice.discountValue ?? null,
discountType: invoice.discountType ?? null,
discountAmount: invoice.discountAmount ?? null,
taxRate: invoice.taxRate ?? null,
},
items,
client: {
name: client?.name || "Deleted Client",
email: client?.email || null,
street: client?.street || null,
city: client?.city || null,
state: client?.state || null,
zip: client?.zip || null,
country: client?.country || null,
},
organization: {
name: organization.name,
street: organization.street || null,
city: organization.city || null,
state: organization.state || null,
zip: organization.zip || null,
country: organization.country || null,
logoUrl: organization.logoUrl || null,
},
});
if (!user || !id) { const stream = await renderToStream(document);
return new Response("Unauthorized", { status: 401 }); const chunks: Uint8Array[] = [];
for await (const chunk of stream) {
chunks.push(chunk as Uint8Array);
} }
const buffer = Buffer.concat(chunks);
const invoiceResult = await db return new Response(buffer, {
.select({ headers: {
invoice: invoices, "Content-Type": "application/pdf",
client: clients, "Content-Disposition": `attachment; filename="${invoice.number.replace(/[^a-zA-Z0-9_\-\.]/g, "_")}.pdf"`,
organization: organizations, },
}) });
.from(invoices)
.leftJoin(clients, eq(invoices.clientId, clients.id))
.innerJoin(organizations, eq(invoices.organizationId, organizations.id))
.where(eq(invoices.id, id))
.get();
if (!invoiceResult) {
return new Response("Invoice not found", { status: 404 });
}
const { invoice, client, organization } = invoiceResult;
const membership = await db
.select()
.from(members)
.where(
and(
eq(members.userId, user.id),
eq(members.organizationId, invoice.organizationId),
),
)
.get();
if (!membership) {
return new Response("Forbidden", { status: 403 });
}
const items = await db
.select()
.from(invoiceItems)
.where(eq(invoiceItems.invoiceId, invoice.id))
.all();
if (!client) {
return new Response("Client not found", { status: 404 });
}
const originalConsoleLog = console.log;
const originalConsoleWarn = console.warn;
console.log = () => {};
console.warn = () => {};
try {
const pdfDocument = createInvoiceDocument({
invoice,
items,
client,
organization,
});
const stream = await renderToStream(pdfDocument);
console.log = originalConsoleLog;
console.warn = originalConsoleWarn;
const filename = `${invoice.type}_${invoice.number.replace(/[^a-zA-Z0-9]/g, "_")}.pdf`;
return new Response(stream as any, {
headers: {
"Content-Type": "application/pdf",
"Content-Disposition": `attachment; filename="${filename}"`,
},
});
} catch (pdfError) {
// Restore console.log on error
console.log = originalConsoleLog;
console.warn = originalConsoleWarn;
throw pdfError;
}
} catch (error) { } catch (error) {
console.error("Error generating PDF:", error); console.error("Error generating PDF:", error);
return new Response("Error generating PDF", { status: 500 }); return new Response("Failed to generate PDF", { status: 500 });
} }
}; };

View File

@@ -0,0 +1,277 @@
import type { APIRoute } from "astro";
import { db } from "../../../../db";
import {
invoices,
invoiceItems,
timeEntries,
members,
tags,
} from "../../../../db/schema";
import {
eq,
and,
gte,
lte,
isNull,
isNotNull,
inArray,
sql,
desc,
} from "drizzle-orm";
import { nanoid } from "nanoid";
export const POST: APIRoute = async ({ request, params, locals, redirect }) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
const { id } = params;
if (!id) {
return new Response("Invoice ID is required", { status: 400 });
}
const formData = await request.formData();
const startDateStr = formData.get("startDate") as string;
const endDateStr = formData.get("endDate") as string;
const groupByDay = formData.get("groupByDay") === "on";
if (!startDateStr || !endDateStr) {
return new Response("Start date and end date are required", {
status: 400,
});
}
const startDate = new Date(startDateStr);
const endDate = new Date(endDateStr);
// Set end date to end of day
endDate.setHours(23, 59, 59, 999);
const invoice = await db
.select()
.from(invoices)
.where(eq(invoices.id, id))
.get();
if (!invoice) {
return new Response("Invoice not found", { status: 404 });
}
const membership = await db
.select()
.from(members)
.where(
and(
eq(members.userId, user.id),
eq(members.organizationId, invoice.organizationId),
),
)
.get();
if (!membership) {
return new Response("Not authorized", { status: 403 });
}
if (invoice.status !== "draft") {
return new Response("Can only import time into draft invoices", {
status: 400,
});
}
const entries = await db
.select({
entry: timeEntries,
tag: tags,
})
.from(timeEntries)
.leftJoin(tags, eq(timeEntries.tagId, tags.id))
.where(
and(
eq(timeEntries.organizationId, invoice.organizationId),
eq(timeEntries.clientId, invoice.clientId),
isNull(timeEntries.invoiceId),
isNotNull(timeEntries.endTime),
gte(timeEntries.startTime, startDate),
lte(timeEntries.startTime, endDate),
),
)
.orderBy(desc(timeEntries.startTime));
const processedEntries = new Map<
string,
{
entry: typeof timeEntries.$inferSelect;
rates: number[];
tagNames: string[];
}
>();
for (const { entry, tag } of entries) {
if (!processedEntries.has(entry.id)) {
processedEntries.set(entry.id, {
entry,
rates: [],
tagNames: [],
});
}
const current = processedEntries.get(entry.id)!;
if (tag) {
if (tag.rate && tag.rate > 0) {
current.rates.push(tag.rate);
}
current.tagNames.push(tag.name);
}
}
const newItems: {
id: string;
invoiceId: string;
description: string;
quantity: number;
unitPrice: number;
amount: number;
}[] = [];
const entryIdsToUpdate: string[] = [];
if (groupByDay) {
// Group by YYYY-MM-DD
const days = new Map<
string,
{
date: string;
totalDuration: number; // milliseconds
totalAmount: number; // cents
entries: string[]; // ids
}
>();
for (const { entry, rates } of processedEntries.values()) {
if (!entry.endTime) continue;
const dateKey = entry.startTime.toISOString().split("T")[0];
const duration = entry.endTime.getTime() - entry.startTime.getTime();
const hours = duration / (1000 * 60 * 60);
// Determine rate: max of tags, or 0
const rate = rates.length > 0 ? Math.max(...rates) : 0;
const amount = Math.round(hours * rate);
if (!days.has(dateKey)) {
days.set(dateKey, {
date: dateKey,
totalDuration: 0,
totalAmount: 0,
entries: [],
});
}
const day = days.get(dateKey)!;
day.totalDuration += duration;
day.totalAmount += amount;
day.entries.push(entry.id);
entryIdsToUpdate.push(entry.id);
}
for (const day of days.values()) {
const hours = day.totalDuration / (1000 * 60 * 60);
// Avoid division by zero
const unitPrice = hours > 0 ? Math.round(day.totalAmount / hours) : 0;
newItems.push({
id: nanoid(),
invoiceId: invoice.id,
description: `Time entries for ${day.date} (${day.entries.length} entries)`,
quantity: parseFloat(hours.toFixed(2)),
unitPrice,
amount: day.totalAmount,
});
}
} else {
// Individual items
for (const { entry, rates, tagNames } of processedEntries.values()) {
if (!entry.endTime) continue;
const duration = entry.endTime.getTime() - entry.startTime.getTime();
const hours = duration / (1000 * 60 * 60);
// Determine rate: max of tags, or 0
const rate = rates.length > 0 ? Math.max(...rates) : 0;
const amount = Math.round(hours * rate);
let description = entry.description || "Time Entry";
const dateStr = entry.startTime.toLocaleDateString();
description = `[${dateStr}] ${description}`;
if (tagNames.length > 0) {
description += ` (${tagNames.join(", ")})`;
}
newItems.push({
id: nanoid(),
invoiceId: invoice.id,
description,
quantity: parseFloat(hours.toFixed(2)),
unitPrice: rate,
amount,
});
entryIdsToUpdate.push(entry.id);
}
}
if (newItems.length === 0) {
return redirect(`/dashboard/invoices/${id}?error=no-entries`);
}
try {
await db.transaction(async (tx) => {
await tx.insert(invoiceItems).values(newItems);
if (entryIdsToUpdate.length > 0) {
await tx
.update(timeEntries)
.set({ invoiceId: invoice.id })
.where(inArray(timeEntries.id, entryIdsToUpdate));
}
const allItems = await tx
.select()
.from(invoiceItems)
.where(eq(invoiceItems.invoiceId, invoice.id));
const subtotal = allItems.reduce((sum, item) => sum + item.amount, 0);
let discountAmount = 0;
if (invoice.discountType === "percentage") {
discountAmount = Math.round(
subtotal * ((invoice.discountValue || 0) / 100),
);
} else {
discountAmount = Math.round((invoice.discountValue || 0) * 100);
if (invoice.discountValue && invoice.discountValue > 0) {
discountAmount = Math.round((invoice.discountValue || 0) * 100);
}
}
const taxableAmount = Math.max(0, subtotal - discountAmount);
const taxAmount = Math.round(
taxableAmount * ((invoice.taxRate || 0) / 100),
);
const total = subtotal - discountAmount + taxAmount;
await tx
.update(invoices)
.set({
subtotal,
discountAmount,
taxAmount,
total,
})
.where(eq(invoices.id, invoice.id));
});
return redirect(`/dashboard/invoices/${id}?success=imported`);
} catch (error) {
console.error("Error importing time entries:", error);
return new Response("Failed to import time entries", { status: 500 });
}
};

View File

@@ -3,6 +3,7 @@ import { db } from "../../../../../db";
import { invoiceItems, invoices, members } from "../../../../../db/schema"; import { invoiceItems, invoices, members } from "../../../../../db/schema";
import { eq, and } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
import { recalculateInvoiceTotals } from "../../../../../utils/invoice"; import { recalculateInvoiceTotals } from "../../../../../utils/invoice";
import { MAX_LENGTHS, exceedsLength } from "../../../../../lib/validation";
export const POST: APIRoute = async ({ export const POST: APIRoute = async ({
request, request,
@@ -61,6 +62,11 @@ export const POST: APIRoute = async ({
return new Response("Missing required fields", { status: 400 }); return new Response("Missing required fields", { status: 400 });
} }
const lengthError = exceedsLength("Description", description, MAX_LENGTHS.itemDescription);
if (lengthError) {
return new Response(lengthError, { status: 400 });
}
const quantity = parseFloat(quantityStr); const quantity = parseFloat(quantityStr);
const unitPriceMajor = parseFloat(unitPriceStr); const unitPriceMajor = parseFloat(unitPriceStr);

View File

@@ -60,6 +60,13 @@ export const POST: APIRoute = async ({
return new Response("Unauthorized", { status: 401 }); return new Response("Unauthorized", { status: 401 });
} }
// Destructive status changes require owner/admin
const destructiveStatuses = ["void"];
const isAdminOrOwner = membership.role === "owner" || membership.role === "admin";
if (destructiveStatuses.includes(status) && !isAdminOrOwner) {
return new Response("Only owners and admins can void invoices", { status: 403 });
}
try { try {
await db await db
.update(invoices) .update(invoices)

View File

@@ -3,6 +3,7 @@ import { db } from "../../../../db";
import { invoices, members } from "../../../../db/schema"; import { invoices, members } from "../../../../db/schema";
import { eq, and } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
import { recalculateInvoiceTotals } from "../../../../utils/invoice"; import { recalculateInvoiceTotals } from "../../../../utils/invoice";
import { MAX_LENGTHS, exceedsLength } from "../../../../lib/validation";
export const POST: APIRoute = async ({ request, redirect, locals, params }) => { export const POST: APIRoute = async ({ request, redirect, locals, params }) => {
const user = locals.user; const user = locals.user;
@@ -56,6 +57,14 @@ export const POST: APIRoute = async ({ request, redirect, locals, params }) => {
return new Response("Missing required fields", { status: 400 }); return new Response("Missing required fields", { status: 400 });
} }
const lengthError =
exceedsLength("Invoice number", number, MAX_LENGTHS.invoiceNumber) ||
exceedsLength("Currency", currency, MAX_LENGTHS.currency) ||
exceedsLength("Notes", notes, MAX_LENGTHS.invoiceNotes);
if (lengthError) {
return new Response(lengthError, { status: 400 });
}
try { try {
const issueDate = new Date(issueDateStr); const issueDate = new Date(issueDateStr);
const dueDate = new Date(dueDateStr); const dueDate = new Date(dueDateStr);

View File

@@ -43,6 +43,11 @@ export const POST: APIRoute = async ({ request, redirect, locals }) => {
return new Response("Unauthorized", { status: 401 }); return new Response("Unauthorized", { status: 401 });
} }
const isAdminOrOwner = membership.role === "owner" || membership.role === "admin";
if (!isAdminOrOwner) {
return new Response("Only owners and admins can delete invoices", { status: 403 });
}
try { try {
// Delete invoice items first (manual cascade) // Delete invoice items first (manual cascade)
await db.delete(invoiceItems).where(eq(invoiceItems.invoiceId, invoiceId)); await db.delete(invoiceItems).where(eq(invoiceItems.invoiceId, invoiceId));

View File

@@ -4,6 +4,7 @@ import path from "path";
import { db } from "../../../db"; import { db } from "../../../db";
import { organizations, members } from "../../../db/schema"; import { organizations, members } from "../../../db/schema";
import { eq, and } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
import { MAX_LENGTHS, exceedsLength } from "../../../lib/validation";
export const POST: APIRoute = async ({ request, locals, redirect }) => { export const POST: APIRoute = async ({ request, locals, redirect }) => {
const user = locals.user; const user = locals.user;
@@ -19,6 +20,8 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
const state = formData.get("state") as string | null; const state = formData.get("state") as string | null;
const zip = formData.get("zip") as string | null; const zip = formData.get("zip") as string | null;
const country = formData.get("country") as string | null; const country = formData.get("country") as string | null;
const defaultTaxRate = formData.get("defaultTaxRate") as string | null;
const defaultCurrency = formData.get("defaultCurrency") as string | null;
const logo = formData.get("logo") as File | null; const logo = formData.get("logo") as File | null;
if (!organizationId || !name || name.trim().length === 0) { if (!organizationId || !name || name.trim().length === 0) {
@@ -27,6 +30,18 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
}); });
} }
const lengthError =
exceedsLength("Name", name, MAX_LENGTHS.name) ||
exceedsLength("Street", street, MAX_LENGTHS.address) ||
exceedsLength("City", city, MAX_LENGTHS.address) ||
exceedsLength("State", state, MAX_LENGTHS.address) ||
exceedsLength("ZIP", zip, MAX_LENGTHS.address) ||
exceedsLength("Country", country, MAX_LENGTHS.address) ||
exceedsLength("Currency", defaultCurrency, MAX_LENGTHS.currency);
if (lengthError) {
return new Response(lengthError, { status: 400 });
}
try { try {
// Verify user is admin/owner of this organization // Verify user is admin/owner of this organization
const membership = await db const membership = await db
@@ -65,7 +80,9 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
); );
} }
const ext = logo.name.split(".").pop() || "png"; const rawExt = (logo.name.split(".").pop() || "png").toLowerCase().replace(/[^a-z]/g, "");
const allowedExtensions = ["png", "jpg", "jpeg"];
const ext = allowedExtensions.includes(rawExt) ? rawExt : "png";
const filename = `${organizationId}-${Date.now()}.${ext}`; const filename = `${organizationId}-${Date.now()}.${ext}`;
const dataDir = process.env.DATA_DIR const dataDir = process.env.DATA_DIR
? process.env.DATA_DIR ? process.env.DATA_DIR
@@ -96,6 +113,8 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
state: state?.trim() || null, state: state?.trim() || null,
zip: zip?.trim() || null, zip: zip?.trim() || null,
country: country?.trim() || null, country: country?.trim() || null,
defaultTaxRate: defaultTaxRate ? parseFloat(defaultTaxRate) : 0,
defaultCurrency: defaultCurrency || "USD",
}; };
if (logoUrl) { if (logoUrl) {

View File

@@ -1,72 +1,89 @@
import type { APIRoute } from 'astro'; import type { APIRoute } from "astro";
import { db } from '../../../db'; import { db } from "../../../db";
import { timeEntries, members, users, clients, categories } from '../../../db/schema'; import { timeEntries, members, users, clients, tags } from "../../../db/schema";
import { eq, and, gte, lte, desc } from 'drizzle-orm'; import { eq, and, gte, lte, desc } from "drizzle-orm";
export const GET: APIRoute = async ({ request, locals, cookies }) => { export const GET: APIRoute = async ({ request, locals, cookies }) => {
const user = locals.user; const user = locals.user;
if (!user) { if (!user) {
return new Response('Unauthorized', { status: 401 }); return new Response("Unauthorized", { status: 401 });
} }
// Get current team from cookie // Get current team from cookie
const currentTeamId = cookies.get('currentTeamId')?.value; const currentTeamId = cookies.get("currentTeamId")?.value;
const userMemberships = await db.select() const userMemberships = await db
.select()
.from(members) .from(members)
.where(eq(members.userId, user.id)) .where(eq(members.userId, user.id))
.all(); .all();
if (userMemberships.length === 0) { if (userMemberships.length === 0) {
return new Response('No organization found', { status: 404 }); return new Response("No organization found", { status: 404 });
} }
// Use current team or fallback to first membership // Use current team or fallback to first membership
const userMembership = currentTeamId const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0] ? userMemberships.find((m) => m.organizationId === currentTeamId) ||
userMemberships[0]
: userMemberships[0]; : userMemberships[0];
const url = new URL(request.url); const url = new URL(request.url);
const selectedMemberId = url.searchParams.get('member') || ''; const selectedMemberId = url.searchParams.get("member") || "";
const selectedCategoryId = url.searchParams.get('category') || ''; const selectedClientId = url.searchParams.get("client") || "";
const selectedClientId = url.searchParams.get('client') || ''; const timeRange = url.searchParams.get("range") || "week";
const timeRange = url.searchParams.get('range') || 'week'; const customFrom = url.searchParams.get("from");
const customFrom = url.searchParams.get('from'); const customTo = url.searchParams.get("to");
const customTo = url.searchParams.get('to');
const now = new Date(); const now = new Date();
let startDate = new Date(); let startDate = new Date();
let endDate = new Date(); let endDate = new Date();
switch (timeRange) { switch (timeRange) {
case 'today': case "today":
startDate.setHours(0, 0, 0, 0); startDate.setHours(0, 0, 0, 0);
endDate.setHours(23, 59, 59, 999); endDate.setHours(23, 59, 59, 999);
break; break;
case 'week': case "week":
startDate.setDate(now.getDate() - 7); startDate.setDate(now.getDate() - 7);
break; break;
case 'month': case "month":
startDate.setMonth(now.getMonth() - 1); startDate.setMonth(now.getMonth() - 1);
break; break;
case 'mtd': case "mtd":
startDate = new Date(now.getFullYear(), now.getMonth(), 1); startDate = new Date(now.getFullYear(), now.getMonth(), 1);
break; break;
case 'ytd': case "ytd":
startDate = new Date(now.getFullYear(), 0, 1); startDate = new Date(now.getFullYear(), 0, 1);
break; break;
case 'last-month': case "last-month":
startDate = new Date(now.getFullYear(), now.getMonth() - 1, 1); startDate = new Date(now.getFullYear(), now.getMonth() - 1, 1);
endDate = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59, 999); endDate = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59, 999);
break; break;
case 'custom': case "custom":
if (customFrom) { if (customFrom) {
const parts = customFrom.split('-'); const parts = customFrom.split("-");
startDate = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]), 0, 0, 0, 0); startDate = new Date(
parseInt(parts[0]),
parseInt(parts[1]) - 1,
parseInt(parts[2]),
0,
0,
0,
0,
);
} }
if (customTo) { if (customTo) {
const parts = customTo.split('-'); const parts = customTo.split("-");
endDate = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]), 23, 59, 59, 999); endDate = new Date(
parseInt(parts[0]),
parseInt(parts[1]) - 1,
parseInt(parts[2]),
23,
59,
59,
999,
);
} }
break; break;
} }
@@ -81,31 +98,44 @@ export const GET: APIRoute = async ({ request, locals, cookies }) => {
conditions.push(eq(timeEntries.userId, selectedMemberId)); conditions.push(eq(timeEntries.userId, selectedMemberId));
} }
if (selectedCategoryId) {
conditions.push(eq(timeEntries.categoryId, selectedCategoryId));
}
if (selectedClientId) { if (selectedClientId) {
conditions.push(eq(timeEntries.clientId, selectedClientId)); conditions.push(eq(timeEntries.clientId, selectedClientId));
} }
const entries = await db.select({ const entries = await db
entry: timeEntries, .select({
user: users, entry: timeEntries,
client: clients, user: users,
category: categories, client: clients,
}) tag: tags,
})
.from(timeEntries) .from(timeEntries)
.innerJoin(users, eq(timeEntries.userId, users.id)) .innerJoin(users, eq(timeEntries.userId, users.id))
.innerJoin(clients, eq(timeEntries.clientId, clients.id)) .innerJoin(clients, eq(timeEntries.clientId, clients.id))
.innerJoin(categories, eq(timeEntries.categoryId, categories.id)) .leftJoin(tags, eq(timeEntries.tagId, tags.id))
.where(and(...conditions)) .where(and(...conditions))
.orderBy(desc(timeEntries.startTime)) .orderBy(desc(timeEntries.startTime))
.all(); .all();
// Generate CSV // Generate CSV
const headers = ['Date', 'Start Time', 'End Time', 'Duration (h)', 'Member', 'Client', 'Category', 'Description']; const headers = [
const rows = entries.map(e => { "Date",
"Start Time",
"End Time",
"Duration (h)",
"Member",
"Client",
"Tag",
"Description",
];
const sanitizeCell = (value: string): string => {
if (/^[=+\-@\t\r]/.test(value)) {
return `\t${value}`;
}
return value;
};
const rows = entries.map((e) => {
const start = e.entry.startTime; const start = e.entry.startTime;
const end = e.entry.endTime; const end = e.entry.endTime;
@@ -114,24 +144,26 @@ export const GET: APIRoute = async ({ request, locals, cookies }) => {
duration = (end.getTime() - start.getTime()) / (1000 * 60 * 60); // Hours duration = (end.getTime() - start.getTime()) / (1000 * 60 * 60); // Hours
} }
const tagsStr = e.tag?.name || "";
return [ return [
start.toLocaleDateString(), start.toLocaleDateString(),
start.toLocaleTimeString(), start.toLocaleTimeString(),
end ? end.toLocaleTimeString() : '', end ? end.toLocaleTimeString() : "",
end ? duration.toFixed(2) : 'Running', end ? duration.toFixed(2) : "Running",
`"${(e.user.name || '').replace(/"/g, '""')}"`, `"${sanitizeCell((e.user.name || "").replace(/"/g, '""'))}"`,
`"${(e.client.name || '').replace(/"/g, '""')}"`, `"${sanitizeCell((e.client.name || "").replace(/"/g, '""'))}"`,
`"${(e.category.name || '').replace(/"/g, '""')}"`, `"${sanitizeCell(tagsStr.replace(/"/g, '""'))}"`,
`"${(e.entry.description || '').replace(/"/g, '""')}"` `"${sanitizeCell((e.entry.description || "").replace(/"/g, '""'))}"`,
].join(','); ].join(",");
}); });
const csvContent = [headers.join(','), ...rows].join('\n'); const csvContent = [headers.join(","), ...rows].join("\n");
return new Response(csvContent, { return new Response(csvContent, {
headers: { headers: {
'Content-Type': 'text/csv', "Content-Type": "text/csv",
'Content-Disposition': `attachment; filename="time-entries-${startDate.toISOString().split('T')[0]}-to-${endDate.toISOString().split('T')[0]}.csv"`, "Content-Disposition": `attachment; filename="time-entries-${startDate.toISOString().split("T")[0]}-to-${endDate.toISOString().split("T")[0]}.csv"`,
}, },
}); });
}; };

View File

@@ -0,0 +1,57 @@
import type { APIRoute } from "astro";
import { db } from "../../../../db";
import { tags, members, timeEntries } from "../../../../db/schema";
import { eq, and } from "drizzle-orm";
export const POST: APIRoute = async ({ params, locals, redirect }) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
const { id } = params;
if (!id) {
return new Response("Tag ID is required", { status: 400 });
}
// Get the tag to check organization
const tag = await db.select().from(tags).where(eq(tags.id, id)).get();
if (!tag) {
return new Response("Tag not found", { status: 404 });
}
// Verify membership and permissions
const membership = await db
.select()
.from(members)
.where(
and(
eq(members.userId, user.id),
eq(members.organizationId, tag.organizationId),
),
)
.get();
if (!membership) {
return new Response("Not authorized", { status: 403 });
}
const isAdmin = membership.role === "owner" || membership.role === "admin";
if (!isAdmin) {
return new Response("Only owners and admins can manage tags", {
status: 403,
});
}
// Remove tag from time entries
await db
.update(timeEntries)
.set({ tagId: null })
.where(eq(timeEntries.tagId, id));
// Delete the tag
await db.delete(tags).where(eq(tags.id, id));
return redirect("/dashboard/team/settings?success=tags");
};

View File

@@ -0,0 +1,77 @@
import type { APIRoute } from "astro";
import { db } from "../../../../db";
import { tags, members } from "../../../../db/schema";
import { eq, and } from "drizzle-orm";
export const POST: APIRoute = async ({
request,
params,
locals,
redirect,
}) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
const { id } = params;
if (!id) {
return new Response("Tag ID is required", { status: 400 });
}
let name: string | undefined;
let color: string | undefined;
let rate: number | undefined;
if (request.headers.get("Content-Type")?.includes("application/json")) {
const body = await request.json();
name = body.name;
color = body.color;
rate = body.rate !== undefined ? parseInt(body.rate) : undefined;
} else {
const formData = await request.formData();
name = formData.get("name")?.toString();
color = formData.get("color")?.toString();
const rateStr = formData.get("rate")?.toString();
rate = rateStr ? parseInt(rateStr) : undefined;
}
// Get the tag to check organization
const tag = await db.select().from(tags).where(eq(tags.id, id)).get();
if (!tag) {
return new Response("Tag not found", { status: 404 });
}
// Verify membership and permissions
const membership = await db
.select()
.from(members)
.where(
and(
eq(members.userId, user.id),
eq(members.organizationId, tag.organizationId),
),
)
.get();
if (!membership) {
return new Response("Not authorized", { status: 403 });
}
const isAdmin = membership.role === "owner" || membership.role === "admin";
if (!isAdmin) {
return new Response("Only owners and admins can manage tags", {
status: 403,
});
}
const updateData: any = {};
if (name) updateData.name = name;
if (color) updateData.color = color;
if (rate !== undefined) updateData.rate = rate;
await db.update(tags).set(updateData).where(eq(tags.id, id));
return redirect("/dashboard/team/settings?success=tags");
};

View File

@@ -0,0 +1,72 @@
import type { APIRoute } from "astro";
import { db } from "../../../db";
import { tags, members } from "../../../db/schema";
import { eq, and } from "drizzle-orm";
import { nanoid } from "nanoid";
export const POST: APIRoute = async ({ request, locals, redirect }) => {
const user = locals.user;
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
let name: string | undefined;
let color: string | undefined;
let rate: number | undefined;
let organizationId: string | undefined;
if (request.headers.get("Content-Type")?.includes("application/json")) {
const body = await request.json();
name = body.name;
color = body.color;
rate = body.rate ? parseInt(body.rate) : 0;
organizationId = body.organizationId;
} else {
const formData = await request.formData();
name = formData.get("name")?.toString();
color = formData.get("color")?.toString();
const rateStr = formData.get("rate")?.toString();
rate = rateStr ? parseInt(rateStr) : 0;
organizationId = formData.get("organizationId")?.toString();
}
if (!name || !organizationId) {
return new Response("Name and Organization ID are required", {
status: 400,
});
}
// Verify membership and permissions
const membership = await db
.select()
.from(members)
.where(
and(
eq(members.userId, user.id),
eq(members.organizationId, organizationId),
),
)
.get();
if (!membership) {
return new Response("Not authorized", { status: 403 });
}
const isAdmin = membership.role === "owner" || membership.role === "admin";
if (!isAdmin) {
return new Response("Only owners and admins can manage tags", {
status: 403,
});
}
const id = nanoid();
await db.insert(tags).values({
id,
organizationId,
name,
color: color || null,
rate: rate || 0,
});
return redirect("/dashboard/team/settings?success=tags");
};

View File

@@ -2,6 +2,7 @@ import type { APIRoute } from 'astro';
import { db } from '../../../db'; import { db } from '../../../db';
import { users, members } from '../../../db/schema'; import { users, members } from '../../../db/schema';
import { eq, and } from 'drizzle-orm'; import { eq, and } from 'drizzle-orm';
import { isValidEmail } from '../../../lib/validation';
export const POST: APIRoute = async ({ request, locals, redirect }) => { export const POST: APIRoute = async ({ request, locals, redirect }) => {
const user = locals.user; const user = locals.user;
@@ -26,6 +27,10 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
return new Response('Email is required', { status: 400 }); return new Response('Email is required', { status: 400 });
} }
if (!isValidEmail(email)) {
return new Response('Invalid email format', { status: 400 });
}
if (!['member', 'admin'].includes(role)) { if (!['member', 'admin'].includes(role)) {
return new Response('Invalid role', { status: 400 }); return new Response('Invalid role', { status: 400 });
} }

View File

@@ -1,11 +1,12 @@
import type { APIRoute } from "astro"; import type { APIRoute } from "astro";
import { db } from "../../../db"; import { db } from "../../../db";
import { timeEntries, members, timeEntryTags } from "../../../db/schema"; import { timeEntries, members } from "../../../db/schema";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
import { import {
validateTimeEntryResources, validateTimeEntryResources,
validateTimeRange, validateTimeRange,
MAX_LENGTHS,
} from "../../../lib/validation"; } from "../../../lib/validation";
export const POST: APIRoute = async ({ request, locals }) => { export const POST: APIRoute = async ({ request, locals }) => {
@@ -17,7 +18,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
} }
const body = await request.json(); const body = await request.json();
const { description, clientId, categoryId, startTime, endTime, tags } = body; const { description, clientId, startTime, endTime, tagId } = body;
// Validation // Validation
if (!clientId) { if (!clientId) {
@@ -27,11 +28,11 @@ export const POST: APIRoute = async ({ request, locals }) => {
}); });
} }
if (!categoryId) { if (description && description.length > MAX_LENGTHS.description) {
return new Response(JSON.stringify({ error: "Category is required" }), { return new Response(
status: 400, JSON.stringify({ error: `Description must be ${MAX_LENGTHS.description} characters or fewer` }),
headers: { "Content-Type": "application/json" }, { status: 400, headers: { "Content-Type": "application/json" } },
}); );
} }
if (!startTime) { if (!startTime) {
@@ -81,8 +82,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
const resourceValidation = await validateTimeEntryResources({ const resourceValidation = await validateTimeEntryResources({
organizationId: member.organizationId, organizationId: member.organizationId,
clientId, clientId,
categoryId, tagId: tagId || null,
tagIds: Array.isArray(tags) ? tags : undefined,
}); });
if (!resourceValidation.valid) { if (!resourceValidation.valid) {
@@ -101,23 +101,13 @@ export const POST: APIRoute = async ({ request, locals }) => {
userId: locals.user.id, userId: locals.user.id,
organizationId: member.organizationId, organizationId: member.organizationId,
clientId, clientId,
categoryId, tagId: tagId || null,
startTime: startDate, startTime: startDate,
endTime: endDate, endTime: endDate,
description: description || null, description: description || null,
isManual: true, isManual: true,
}); });
// Insert tags if provided
if (tags && Array.isArray(tags) && tags.length > 0) {
await db.insert(timeEntryTags).values(
tags.map((tagId: string) => ({
timeEntryId: id,
tagId,
})),
);
}
return new Response( return new Response(
JSON.stringify({ JSON.stringify({
success: true, success: true,

View File

@@ -1,9 +1,9 @@
import type { APIRoute } from "astro"; import type { APIRoute } from "astro";
import { db } from "../../../db"; import { db } from "../../../db";
import { timeEntries, members, timeEntryTags } from "../../../db/schema"; import { timeEntries, members } from "../../../db/schema";
import { eq, and, isNull } from "drizzle-orm"; import { eq, and, isNull } from "drizzle-orm";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
import { validateTimeEntryResources } from "../../../lib/validation"; import { validateTimeEntryResources, MAX_LENGTHS } from "../../../lib/validation";
export const POST: APIRoute = async ({ request, locals }) => { export const POST: APIRoute = async ({ request, locals }) => {
if (!locals.user) return new Response("Unauthorized", { status: 401 }); if (!locals.user) return new Response("Unauthorized", { status: 401 });
@@ -11,15 +11,14 @@ export const POST: APIRoute = async ({ request, locals }) => {
const body = await request.json(); const body = await request.json();
const description = body.description || ""; const description = body.description || "";
const clientId = body.clientId; const clientId = body.clientId;
const categoryId = body.categoryId; const tagId = body.tagId || null;
const tags = body.tags || [];
if (!clientId) { if (!clientId) {
return new Response("Client is required", { status: 400 }); return new Response("Client is required", { status: 400 });
} }
if (!categoryId) { if (description && description.length > MAX_LENGTHS.description) {
return new Response("Category is required", { status: 400 }); return new Response(`Description must be ${MAX_LENGTHS.description} characters or fewer`, { status: 400 });
} }
const runningEntry = await db const runningEntry = await db
@@ -47,8 +46,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
const validation = await validateTimeEntryResources({ const validation = await validateTimeEntryResources({
organizationId: member.organizationId, organizationId: member.organizationId,
clientId, clientId,
categoryId, tagId,
tagIds: tags,
}); });
if (!validation.valid) { if (!validation.valid) {
@@ -63,20 +61,11 @@ export const POST: APIRoute = async ({ request, locals }) => {
userId: locals.user.id, userId: locals.user.id,
organizationId: member.organizationId, organizationId: member.organizationId,
clientId, clientId,
categoryId, tagId,
startTime, startTime,
description, description,
isManual: false, isManual: false,
}); });
if (tags.length > 0) {
await db.insert(timeEntryTags).values(
tags.map((tagId: string) => ({
timeEntryId: id,
tagId,
})),
);
}
return new Response(JSON.stringify({ id, startTime }), { status: 200 }); return new Response(JSON.stringify({ id, startTime }), { status: 200 });
}; };

View File

@@ -1,10 +1,11 @@
import type { APIRoute } from "astro"; import type { APIRoute } from "astro";
import { db } from "../../../db"; import { db } from "../../../db";
import { users } from "../../../db/schema"; import { users, sessions } from "../../../db/schema";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import bcrypt from "bcryptjs"; import bcrypt from "bcryptjs";
import { MAX_LENGTHS } from "../../../lib/validation";
export const POST: APIRoute = async ({ request, locals, redirect }) => { export const POST: APIRoute = async ({ request, locals, redirect, cookies }) => {
const user = locals.user; const user = locals.user;
const contentType = request.headers.get("content-type"); const contentType = request.headers.get("content-type");
const isJson = contentType?.includes("application/json"); const isJson = contentType?.includes("application/json");
@@ -53,6 +54,13 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
return new Response(msg, { status: 400 }); return new Response(msg, { status: 400 });
} }
if (currentPassword.length > MAX_LENGTHS.password || newPassword.length > MAX_LENGTHS.password) {
const msg = `Password must be ${MAX_LENGTHS.password} characters or fewer`;
if (isJson)
return new Response(JSON.stringify({ error: msg }), { status: 400 });
return new Response(msg, { status: 400 });
}
try { try {
// Get current user from database // Get current user from database
const dbUser = await db const dbUser = await db
@@ -90,6 +98,32 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
.where(eq(users.id, user.id)) .where(eq(users.id, user.id))
.run(); .run();
// Invalidate all sessions, then re-create one for the current user
const currentSessionId = cookies.get("session_id")?.value;
if (currentSessionId) {
await db
.delete(sessions)
.where(
eq(sessions.userId, user.id),
)
.run();
const { createSession } = await import("../../../lib/auth");
const { sessionId, expiresAt } = await createSession(user.id);
cookies.set("session_id", sessionId, {
path: "/",
httpOnly: true,
secure: import.meta.env.PROD,
sameSite: "lax",
expires: expiresAt,
});
} else {
await db
.delete(sessions)
.where(eq(sessions.userId, user.id))
.run();
}
if (isJson) { if (isJson) {
return new Response(JSON.stringify({ success: true }), { status: 200 }); return new Response(JSON.stringify({ success: true }), { status: 200 });
} }

View File

@@ -1,62 +0,0 @@
---
import DashboardLayout from '../../layouts/DashboardLayout.astro';
import { db } from '../../db';
import { categories, members } from '../../db/schema';
import { eq } from 'drizzle-orm';
const user = Astro.locals.user;
if (!user) return Astro.redirect('/login');
// Get current team from cookie
const currentTeamId = Astro.cookies.get('currentTeamId')?.value;
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const allCategories = await db.select()
.from(categories)
.where(eq(categories.organizationId, userMembership.organizationId))
.all();
---
<DashboardLayout title="Categories - Chronus">
<div class="flex justify-between items-center mb-6">
<h1 class="text-3xl font-bold">Categories</h1>
<a href="/dashboard/categories/new" class="btn btn-primary">Add Category</a>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{allCategories.map(category => (
<div class="card bg-base-200 shadow-xl border border-base-300">
<div class="card-body">
<h2 class="card-title">
{category.color && (
<span class="w-4 h-4 rounded-full" style={`background-color: ${category.color}`}></span>
)}
{category.name}
</h2>
<p class="text-xs text-base-content/60">Created {category.createdAt?.toLocaleDateString() ?? 'N/A'}</p>
<div class="card-actions justify-end mt-4">
<a href={`/dashboard/categories/${category.id}/edit`} class="btn btn-sm btn-primary">Edit</a>
</div>
</div>
</div>
))}
</div>
{allCategories.length === 0 && (
<div class="text-center py-12">
<p class="text-base-content/60 mb-4">No categories yet</p>
<a href="/dashboard/categories/new" class="btn btn-primary">Add Your First Category</a>
</div>
)}
</DashboardLayout>

View File

@@ -1,99 +0,0 @@
---
import DashboardLayout from '../../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components';
import { db } from '../../../../db';
import { categories, members } from '../../../../db/schema';
import { eq, and } from 'drizzle-orm';
const user = Astro.locals.user;
if (!user) return Astro.redirect('/login');
const { id } = Astro.params;
// Get current team from cookie
const currentTeamId = Astro.cookies.get('currentTeamId')?.value;
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const isAdmin = userMembership.role === 'owner' || userMembership.role === 'admin';
if (!isAdmin) return Astro.redirect('/dashboard/categories');
const category = await db.select()
.from(categories)
.where(and(
eq(categories.id, id!),
eq(categories.organizationId, userMembership.organizationId)
))
.get();
if (!category) return Astro.redirect('/dashboard/categories');
---
<DashboardLayout title="Edit Category - Chronus">
<div class="max-w-2xl mx-auto">
<div class="flex items-center gap-3 mb-6">
<a href="/dashboard/categories" class="btn btn-ghost btn-sm">
<Icon name="heroicons:arrow-left" class="w-5 h-5" />
</a>
<h1 class="text-3xl font-bold">Edit Category</h1>
</div>
<div class="card bg-base-200 shadow-xl border border-base-300">
<div class="card-body">
<form id="update-form" method="POST" action={`/api/categories/${id}/update`}>
<input type="hidden" name="redirectTo" value="/dashboard/categories" />
<div class="form-control">
<label class="label pb-2" for="name">
<span class="label-text font-medium">Category Name</span>
</label>
<input
type="text"
id="name"
name="name"
value={category.name}
placeholder="Development"
class="input input-bordered w-full"
required
/>
</div>
<div class="form-control mt-4">
<label class="label pb-2" for="color">
<span class="label-text font-medium">Color (optional)</span>
</label>
<input
type="color"
id="color"
name="color"
value={category.color || '#3b82f6'}
class="input input-bordered w-full h-12"
/>
</div>
</form>
<div class="card-actions justify-between mt-6">
<form method="POST" action={`/api/categories/${id}/delete`} onsubmit="return confirm('Are you sure you want to delete this category?');">
<input type="hidden" name="redirectTo" value="/dashboard/categories" />
<button type="submit" class="btn btn-error btn-outline">Delete Category</button>
</form>
<div class="flex gap-2">
<a href="/dashboard/categories" class="btn btn-ghost">Cancel</a>
<button type="submit" form="update-form" class="btn btn-primary">Save Changes</button>
</div>
</div>
</div>
</div>
</div>
</DashboardLayout>

View File

@@ -1,54 +0,0 @@
---
import DashboardLayout from '../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components';
const user = Astro.locals.user;
if (!user) return Astro.redirect('/login');
---
<DashboardLayout title="New Category - Chronus">
<div class="max-w-2xl mx-auto">
<div class="flex items-center gap-3 mb-6">
<a href="/dashboard/categories" class="btn btn-ghost btn-sm">
<Icon name="heroicons:arrow-left" class="w-5 h-5" />
</a>
<h1 class="text-3xl font-bold">Add New Category</h1>
</div>
<form method="POST" action="/api/categories/create" class="card bg-base-200 shadow-xl border border-base-300">
<input type="hidden" name="redirectTo" value="/dashboard/categories" />
<div class="card-body">
<div class="form-control">
<label class="label pb-2" for="name">
<span class="label-text font-medium">Category Name</span>
</label>
<input
type="text"
id="name"
name="name"
placeholder="Development"
class="input input-bordered w-full"
required
/>
</div>
<div class="form-control">
<label class="label pb-2" for="color">
<span class="label-text font-medium">Color (optional)</span>
</label>
<input
type="color"
id="color"
name="color"
class="input input-bordered w-full h-12"
/>
</div>
<div class="card-actions justify-end mt-6">
<a href="/dashboard/categories" class="btn btn-ghost">Cancel</a>
<button type="submit" class="btn btn-primary">Create Category</button>
</div>
</div>
</form>
</div>
</DashboardLayout>

View File

@@ -1,26 +1,15 @@
--- ---
import DashboardLayout from '../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../layouts/DashboardLayout.astro';
import { db } from '../../db'; import { db } from '../../db';
import { clients, members } from '../../db/schema'; import { clients } from '../../db/schema';
import { eq, and } from 'drizzle-orm'; import { eq } from 'drizzle-orm';
import { getCurrentTeam } from '../../lib/getCurrentTeam';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const organizationId = userMembership.organizationId; const organizationId = userMembership.organizationId;
@@ -32,20 +21,20 @@ const allClients = await db.select()
<DashboardLayout title="Clients - Chronus"> <DashboardLayout title="Clients - Chronus">
<div class="flex justify-between items-center mb-6"> <div class="flex justify-between items-center mb-6">
<h1 class="text-3xl font-bold">Clients</h1> <h1 class="text-2xl font-extrabold tracking-tight">Clients</h1>
<a href="/dashboard/clients/new" class="btn btn-primary">Add Client</a> <a href="/dashboard/clients/new" class="btn btn-primary btn-sm">Add Client</a>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
{allClients.map(client => ( {allClients.map(client => (
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4 gap-1">
<h2 class="card-title">{client.name}</h2> <h2 class="font-semibold">{client.name}</h2>
{client.email && <p class="text-sm text-gray-500">{client.email}</p>} {client.email && <p class="text-sm text-base-content/60">{client.email}</p>}
<p class="text-xs text-gray-400">Created {client.createdAt?.toLocaleDateString() ?? 'N/A'}</p> <p class="text-xs text-base-content/40">Created {client.createdAt?.toLocaleDateString() ?? 'N/A'}</p>
<div class="card-actions justify-end mt-4"> <div class="card-actions justify-end mt-3">
<a href={`/dashboard/clients/${client.id}`} class="btn btn-sm btn-ghost">View</a> <a href={`/dashboard/clients/${client.id}`} class="btn btn-xs btn-ghost">View</a>
<a href={`/dashboard/clients/${client.id}/edit`} class="btn btn-sm btn-primary">Edit</a> <a href={`/dashboard/clients/${client.id}/edit`} class="btn btn-xs btn-primary">Edit</a>
</div> </div>
</div> </div>
</div> </div>
@@ -53,9 +42,9 @@ const allClients = await db.select()
</div> </div>
{allClients.length === 0 && ( {allClients.length === 0 && (
<div class="text-center py-12"> <div class="flex flex-col items-center justify-center py-12 text-center">
<p class="text-gray-500 mb-4">No clients yet</p> <p class="text-base-content/50 text-sm mb-4">No clients yet</p>
<a href="/dashboard/clients/new" class="btn btn-primary">Add Your First Client</a> <a href="/dashboard/clients/new" class="btn btn-primary btn-sm">Add Your First Client</a>
</div> </div>
)} )}
</DashboardLayout> </DashboardLayout>

View File

@@ -2,8 +2,9 @@
import DashboardLayout from '../../../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components'; import { Icon } from 'astro-icon/components';
import { db } from '../../../../db'; import { db } from '../../../../db';
import { clients, members } from '../../../../db/schema'; import { clients } from '../../../../db/schema';
import { eq, and } from 'drizzle-orm'; import { eq, and } from 'drizzle-orm';
import { getCurrentTeam } from '../../../../lib/getCurrentTeam';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
@@ -11,20 +12,8 @@ if (!user) return Astro.redirect('/login');
const { id } = Astro.params; const { id } = Astro.params;
if (!id) return Astro.redirect('/dashboard/clients'); if (!id) return Astro.redirect('/dashboard/clients');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const client = await db.select() const client = await db.select()
.from(clients) .from(clients)
@@ -40,145 +29,129 @@ if (!client) return Astro.redirect('/dashboard/clients');
<DashboardLayout title={`Edit ${client.name} - Chronus`}> <DashboardLayout title={`Edit ${client.name} - Chronus`}>
<div class="max-w-2xl mx-auto"> <div class="max-w-2xl mx-auto">
<div class="flex items-center gap-3 mb-6"> <div class="flex items-center gap-3 mb-6">
<a href={`/dashboard/clients/${client.id}`} class="btn btn-ghost btn-sm"> <a href={`/dashboard/clients/${client.id}`} class="btn btn-ghost btn-xs">
<Icon name="heroicons:arrow-left" class="w-5 h-5" /> <Icon name="heroicons:arrow-left" class="w-4 h-4" />
</a> </a>
<h1 class="text-3xl font-bold">Edit Client</h1> <h1 class="text-2xl font-extrabold tracking-tight">Edit Client</h1>
</div> </div>
<form method="POST" action={`/api/clients/${client.id}/update`} class="card bg-base-100 shadow-xl border border-base-200"> <form method="POST" action={`/api/clients/${client.id}/update`} class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="name"> <legend class="fieldset-legend text-xs">Client Name</legend>
<span class="label-text">Client Name</span>
</label>
<input <input
type="text" type="text"
id="name" id="name"
name="name" name="name"
value={client.name} value={client.name}
placeholder="Acme Corp" placeholder="Acme Corp"
class="input input-bordered w-full" class="input w-full"
required required
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="email"> <legend class="fieldset-legend text-xs">Email (optional)</legend>
<span class="label-text">Email (optional)</span>
</label>
<input <input
type="email" type="email"
id="email" id="email"
name="email" name="email"
value={client.email || ''} value={client.email || ''}
placeholder="jason.borne@cia.com" placeholder="jason.borne@cia.com"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="phone"> <legend class="fieldset-legend text-xs">Phone (optional)</legend>
<span class="label-text">Phone (optional)</span>
</label>
<input <input
type="tel" type="tel"
id="phone" id="phone"
name="phone" name="phone"
value={client.phone || ''} value={client.phone || ''}
placeholder="+1 (780) 420-1337" placeholder="+1 (780) 420-1337"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="divider">Address Details</div> <div class="divider text-xs text-base-content/40">Address Details</div>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="street"> <legend class="fieldset-legend text-xs">Street Address (optional)</legend>
<span class="label-text">Street Address (optional)</span>
</label>
<input <input
type="text" type="text"
id="street" id="street"
name="street" name="street"
value={client.street || ''} value={client.street || ''}
placeholder="123 Business Rd" placeholder="123 Business Rd"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="city"> <legend class="fieldset-legend text-xs">City (optional)</legend>
<span class="label-text">City (optional)</span>
</label>
<input <input
type="text" type="text"
id="city" id="city"
name="city" name="city"
value={client.city || ''} value={client.city || ''}
placeholder="Edmonton" placeholder="Edmonton"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="state"> <legend class="fieldset-legend text-xs">State / Province (optional)</legend>
<span class="label-text">State / Province (optional)</span>
</label>
<input <input
type="text" type="text"
id="state" id="state"
name="state" name="state"
value={client.state || ''} value={client.state || ''}
placeholder="AB" placeholder="AB"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="zip"> <legend class="fieldset-legend text-xs">Zip / Postal Code (optional)</legend>
<span class="label-text">Zip / Postal Code (optional)</span>
</label>
<input <input
type="text" type="text"
id="zip" id="zip"
name="zip" name="zip"
value={client.zip || ''} value={client.zip || ''}
placeholder="10001" placeholder="10001"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="country"> <legend class="fieldset-legend text-xs">Country (optional)</legend>
<span class="label-text">Country (optional)</span>
</label>
<input <input
type="text" type="text"
id="country" id="country"
name="country" name="country"
value={client.country || ''} value={client.country || ''}
placeholder="Canada" placeholder="Canada"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
</div> </div>
<div class="card-actions justify-between mt-6"> <div class="flex justify-between items-center mt-4">
<button <button
type="button" type="button"
class="btn btn-error btn-outline" class="btn btn-error btn-outline btn-sm"
onclick={`document.getElementById('delete_modal').showModal()`} onclick={`document.getElementById('delete_modal').showModal()`}
> >
Delete Client Delete Client
</button> </button>
<div class="flex gap-2"> <div class="flex gap-2">
<a href={`/dashboard/clients/${client.id}`} class="btn btn-ghost">Cancel</a> <a href={`/dashboard/clients/${client.id}`} class="btn btn-ghost btn-sm">Cancel</a>
<button type="submit" class="btn btn-primary">Save Changes</button> <button type="submit" class="btn btn-primary btn-sm">Save Changes</button>
</div> </div>
</div> </div>
</div> </div>
@@ -188,17 +161,17 @@ if (!client) return Astro.redirect('/dashboard/clients');
<!-- Delete Confirmation Modal --> <!-- Delete Confirmation Modal -->
<dialog id="delete_modal" class="modal"> <dialog id="delete_modal" class="modal">
<div class="modal-box"> <div class="modal-box">
<h3 class="font-bold text-lg text-error">Delete Client?</h3> <h3 class="font-semibold text-base text-error">Delete Client?</h3>
<p class="py-4"> <p class="py-4 text-sm">
Are you sure you want to delete <strong>{client.name}</strong>? Are you sure you want to delete <strong>{client.name}</strong>?
This action cannot be undone and will delete all associated time entries. This action cannot be undone and will delete all associated time entries.
</p> </p>
<div class="modal-action"> <div class="modal-action">
<form method="dialog"> <form method="dialog">
<button class="btn">Cancel</button> <button class="btn btn-sm">Cancel</button>
</form> </form>
<form method="POST" action={`/api/clients/${client.id}/delete`}> <form method="POST" action={`/api/clients/${client.id}/delete`}>
<button type="submit" class="btn btn-error">Delete</button> <button type="submit" class="btn btn-error btn-sm">Delete</button>
</form> </form>
</div> </div>
</div> </div>

View File

@@ -2,9 +2,11 @@
import DashboardLayout from '../../../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components'; import { Icon } from 'astro-icon/components';
import { db } from '../../../../db'; import { db } from '../../../../db';
import { clients, timeEntries, members, categories, users } from '../../../../db/schema'; import { clients, timeEntries, tags, users } from '../../../../db/schema';
import { eq, and, desc, sql } from 'drizzle-orm'; import { eq, and, desc, sql } from 'drizzle-orm';
import { formatTimeRange } from '../../../../lib/formatTime'; import { formatTimeRange } from '../../../../lib/formatTime';
import { getCurrentTeam } from '../../../../lib/getCurrentTeam';
import StatCard from '../../../../components/StatCard.astro';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
@@ -12,20 +14,8 @@ if (!user) return Astro.redirect('/login');
const { id } = Astro.params; const { id } = Astro.params;
if (!id) return Astro.redirect('/dashboard/clients'); if (!id) return Astro.redirect('/dashboard/clients');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const client = await db.select() const client = await db.select()
.from(clients) .from(clients)
@@ -40,12 +30,12 @@ if (!client) return Astro.redirect('/dashboard/clients');
// Get recent activity // Get recent activity
const recentEntries = await db.select({ const recentEntries = await db.select({
entry: timeEntries, entry: timeEntries,
category: categories,
user: users, user: users,
tag: tags,
}) })
.from(timeEntries) .from(timeEntries)
.leftJoin(categories, eq(timeEntries.categoryId, categories.id))
.leftJoin(users, eq(timeEntries.userId, users.id)) .leftJoin(users, eq(timeEntries.userId, users.id))
.leftJoin(tags, eq(timeEntries.tagId, tags.id))
.where(eq(timeEntries.clientId, client.id)) .where(eq(timeEntries.clientId, client.id))
.orderBy(desc(timeEntries.startTime)) .orderBy(desc(timeEntries.startTime))
.limit(10) .limit(10)
@@ -73,34 +63,34 @@ const totalEntriesCount = totalEntriesResult?.count || 0;
<DashboardLayout title={`${client.name} - Clients - Chronus`}> <DashboardLayout title={`${client.name} - Clients - Chronus`}>
<div class="flex items-center gap-3 mb-6"> <div class="flex items-center gap-3 mb-6">
<a href="/dashboard/clients" class="btn btn-ghost btn-sm"> <a href="/dashboard/clients" class="btn btn-ghost btn-xs">
<Icon name="heroicons:arrow-left" class="w-5 h-5" /> <Icon name="heroicons:arrow-left" class="w-4 h-4" />
</a> </a>
<h1 class="text-3xl font-bold">{client.name}</h1> <h1 class="text-2xl font-extrabold tracking-tight">{client.name}</h1>
</div> </div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8"> <div class="grid grid-cols-1 lg:grid-cols-3 gap-3 mb-6">
<!-- Client Details Card --> <!-- Client Details Card -->
<div class="card bg-base-100 shadow-xl border border-base-200 lg:col-span-2"> <div class="card card-border bg-base-100 lg:col-span-2">
<div class="card-body"> <div class="card-body p-4">
<div class="flex justify-between items-start"> <div class="flex justify-between items-start">
<div> <div>
<h2 class="card-title text-2xl mb-1">{client.name}</h2> <h2 class="text-sm font-semibold mb-3">{client.name}</h2>
<div class="space-y-2 mb-4"> <div class="space-y-2 mb-4">
{client.email && ( {client.email && (
<div class="flex items-center gap-2 text-base-content/70"> <div class="flex items-center gap-2 text-base-content/60 text-sm">
<Icon name="heroicons:envelope" class="w-4 h-4" /> <Icon name="heroicons:envelope" class="w-4 h-4" />
<a href={`mailto:${client.email}`} class="link link-hover">{client.email}</a> <a href={`mailto:${client.email}`} class="link link-hover">{client.email}</a>
</div> </div>
)} )}
{client.phone && ( {client.phone && (
<div class="flex items-center gap-2 text-base-content/70"> <div class="flex items-center gap-2 text-base-content/60 text-sm">
<Icon name="heroicons:phone" class="w-4 h-4" /> <Icon name="heroicons:phone" class="w-4 h-4" />
<a href={`tel:${client.phone}`} class="link link-hover">{client.phone}</a> <a href={`tel:${client.phone}`} class="link link-hover">{client.phone}</a>
</div> </div>
)} )}
{(client.street || client.city || client.state || client.zip || client.country) && ( {(client.street || client.city || client.state || client.zip || client.country) && (
<div class="flex items-start gap-2 text-base-content/70"> <div class="flex items-start gap-2 text-base-content/60">
<Icon name="heroicons:map-pin" class="w-4 h-4 mt-0.5" /> <Icon name="heroicons:map-pin" class="w-4 h-4 mt-0.5" />
<div class="text-sm space-y-0.5"> <div class="text-sm space-y-0.5">
{client.street && <div>{client.street}</div>} {client.street && <div>{client.street}</div>}
@@ -116,91 +106,90 @@ const totalEntriesCount = totalEntriesResult?.count || 0;
</div> </div>
</div> </div>
<div class="flex gap-2"> <div class="flex gap-2">
<a href={`/dashboard/clients/${client.id}/edit`} class="btn btn-primary btn-sm"> <a href={`/dashboard/clients/${client.id}/edit`} class="btn btn-primary btn-xs">
<Icon name="heroicons:pencil" class="w-4 h-4" /> <Icon name="heroicons:pencil" class="w-3 h-3" />
Edit Edit
</a> </a>
<form method="POST" action={`/api/clients/${client.id}/delete`} onsubmit="return confirm('Are you sure you want to delete this client? This will also delete all associated time entries.');"> <form method="POST" action={`/api/clients/${client.id}/delete`} onsubmit="return confirm('Are you sure you want to delete this client? This will also delete all associated time entries.');">
<button type="submit" class="btn btn-error btn-outline btn-sm"> <button type="submit" class="btn btn-error btn-outline btn-xs">
<Icon name="heroicons:trash" class="w-4 h-4" /> <Icon name="heroicons:trash" class="w-3 h-3" />
Delete Delete
</button> </button>
</form> </form>
</div> </div>
</div> </div>
<div class="divider"></div> <div class="divider my-2"></div>
<div class="stats shadow w-full"> <div class="grid grid-cols-2 gap-3">
<div class="stat"> <StatCard
<div class="stat-figure text-primary"> title="Total Time Tracked"
<Icon name="heroicons:clock" class="w-8 h-8" /> value={`${totalHours}h ${totalMinutes}m`}
</div> description="Across all projects"
<div class="stat-title">Total Time Tracked</div> icon="heroicons:clock"
<div class="stat-value text-primary">{totalHours}h {totalMinutes}m</div> color="text-primary"
<div class="stat-desc">Across all projects</div> />
</div> <StatCard
title="Total Entries"
<div class="stat"> value={String(totalEntriesCount)}
<div class="stat-figure text-secondary"> description="Recorded entries"
<Icon name="heroicons:list-bullet" class="w-8 h-8" /> icon="heroicons:list-bullet"
</div> color="text-secondary"
<div class="stat-title">Total Entries</div> />
<div class="stat-value text-secondary">{totalEntriesCount}</div>
<div class="stat-desc">Recorded entries</div>
</div>
</div> </div>
</div> </div>
</div> </div>
<!-- Meta Info Card --> <!-- Meta Info Card -->
<div class="card bg-base-100 shadow-xl border border-base-200 h-fit"> <div class="card card-border bg-base-100 h-fit">
<div class="card-body"> <div class="card-body p-4">
<h3 class="card-title text-lg mb-4">Information</h3> <h3 class="text-sm font-semibold mb-3">Information</h3>
<div class="space-y-4"> <div class="space-y-3">
<div> <div>
<div class="text-sm font-medium text-base-content/60">Created</div> <div class="text-xs text-base-content/40">Created</div>
<div>{client.createdAt?.toLocaleDateString() ?? 'N/A'}</div> <div class="text-sm">{client.createdAt?.toLocaleDateString() ?? 'N/A'}</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Recent Activity --> <!-- Recent Activity -->
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-0">
<h2 class="card-title mb-4">Recent Activity</h2> <div class="px-4 py-3 border-b border-base-200">
<h2 class="text-sm font-semibold">Recent Activity</h2>
</div>
{recentEntries.length > 0 ? ( {recentEntries.length > 0 ? (
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Description</th> <th>Description</th>
<th>Category</th> <th>Tag</th>
<th>User</th> <th>User</th>
<th>Date</th> <th>Date</th>
<th>Duration</th> <th>Duration</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{recentEntries.map(({ entry, category, user: entryUser }) => ( {recentEntries.map(({ entry, tag, user: entryUser }) => (
<tr> <tr class="hover">
<td>{entry.description || '-'}</td> <td>{entry.description || '-'}</td>
<td> <td>
{category ? ( {tag ? (
<div class="flex items-center gap-2"> <div class="badge badge-xs badge-outline flex items-center gap-1">
<span class="w-2 h-2 rounded-full" style={`background-color: ${category.color}`}></span> {tag.color && (
<span>{category.name}</span> <span class="w-2 h-2 rounded-full" style={`background-color: ${tag.color}`}></span>
)}
<span>{tag.name}</span>
</div> </div>
) : '-'} ) : '-'}
</td> </td>
<td>{entryUser?.name || 'Unknown'}</td> <td class="text-base-content/60">{entryUser?.name || 'Unknown'}</td>
<td>{entry.startTime.toLocaleDateString()}</td> <td class="text-base-content/40">{entry.startTime.toLocaleDateString()}</td>
<td class="font-mono">{formatTimeRange(entry.startTime, entry.endTime)}</td> <td class="font-mono">{formatTimeRange(entry.startTime, entry.endTime)}</td>
</tr> </tr>
))} ))}
@@ -208,14 +197,14 @@ const totalEntriesCount = totalEntriesResult?.count || 0;
</table> </table>
</div> </div>
) : ( ) : (
<div class="text-center py-8 text-base-content/60"> <div class="text-center py-8 text-base-content/40 text-sm">
No time entries recorded for this client yet. No time entries recorded for this client yet.
</div> </div>
)} )}
{recentEntries.length > 0 && ( {recentEntries.length > 0 && (
<div class="card-actions justify-center mt-4"> <div class="flex justify-center py-3 border-t border-base-200">
<a href={`/dashboard/tracker?client=${client.id}`} class="btn btn-ghost btn-sm"> <a href={`/dashboard/tracker?client=${client.id}`} class="btn btn-ghost btn-xs">
View All Entries View All Entries
</a> </a>
</div> </div>

View File

@@ -7,124 +7,108 @@ if (!user) return Astro.redirect('/login');
<DashboardLayout title="New Client - Chronus"> <DashboardLayout title="New Client - Chronus">
<div class="max-w-2xl mx-auto"> <div class="max-w-2xl mx-auto">
<h1 class="text-3xl font-bold mb-6">Add New Client</h1> <h1 class="text-2xl font-extrabold tracking-tight mb-6">Add New Client</h1>
<form method="POST" action="/api/clients/create" class="card bg-base-100 shadow-xl border border-base-200"> <form method="POST" action="/api/clients/create" class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="name"> <legend class="fieldset-legend text-xs">Client Name</legend>
<span class="label-text">Client Name</span>
</label>
<input <input
type="text" type="text"
id="name" id="name"
name="name" name="name"
placeholder="Acme Corp" placeholder="Acme Corp"
class="input input-bordered w-full" class="input w-full"
required required
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="email"> <legend class="fieldset-legend text-xs">Email (optional)</legend>
<span class="label-text">Email (optional)</span>
</label>
<input <input
type="email" type="email"
id="email" id="email"
name="email" name="email"
placeholder="jason.borne@cia.com" placeholder="jason.borne@cia.com"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="phone"> <legend class="fieldset-legend text-xs">Phone (optional)</legend>
<span class="label-text">Phone (optional)</span>
</label>
<input <input
type="tel" type="tel"
id="phone" id="phone"
name="phone" name="phone"
placeholder="+1 (780) 420-1337" placeholder="+1 (780) 420-1337"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="divider">Address Details</div> <div class="divider text-xs text-base-content/40">Address Details</div>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="street"> <legend class="fieldset-legend text-xs">Street Address (optional)</legend>
<span class="label-text">Street Address (optional)</span>
</label>
<input <input
type="text" type="text"
id="street" id="street"
name="street" name="street"
placeholder="123 Business Rd" placeholder="123 Business Rd"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="city"> <legend class="fieldset-legend text-xs">City (optional)</legend>
<span class="label-text">City (optional)</span>
</label>
<input <input
type="text" type="text"
id="city" id="city"
name="city" name="city"
placeholder="Edmonton" placeholder="Edmonton"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="state"> <legend class="fieldset-legend text-xs">State / Province (optional)</legend>
<span class="label-text">State / Province (optional)</span>
</label>
<input <input
type="text" type="text"
id="state" id="state"
name="state" name="state"
placeholder="AB" placeholder="AB"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="zip"> <legend class="fieldset-legend text-xs">Zip / Postal Code (optional)</legend>
<span class="label-text">Zip / Postal Code (optional)</span>
</label>
<input <input
type="text" type="text"
id="zip" id="zip"
name="zip" name="zip"
placeholder="10001" placeholder="10001"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="country"> <legend class="fieldset-legend text-xs">Country (optional)</legend>
<span class="label-text">Country (optional)</span>
</label>
<input <input
type="text" type="text"
id="country" id="country"
name="country" name="country"
placeholder="Canada" placeholder="Canada"
class="input input-bordered w-full" class="input w-full"
/> />
</div> </fieldset>
</div> </div>
<div class="card-actions justify-end mt-6"> <div class="flex justify-end gap-2 mt-4">
<a href="/dashboard/clients" class="btn btn-ghost">Cancel</a> <a href="/dashboard/clients" class="btn btn-ghost btn-sm">Cancel</a>
<button type="submit" class="btn btn-primary">Create Client</button> <button type="submit" class="btn btn-primary btn-sm">Create Client</button>
</div> </div>
</div> </div>
</form> </form>

View File

@@ -1,8 +1,9 @@
--- ---
import DashboardLayout from '../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components'; import { Icon } from 'astro-icon/components';
import StatCard from '../../components/StatCard.astro';
import { db } from '../../db'; import { db } from '../../db';
import { organizations, members, timeEntries, clients, categories } from '../../db/schema'; import { organizations, members, timeEntries, clients, tags } from '../../db/schema';
import { eq, desc, and, isNull, gte, sql } from 'drizzle-orm'; import { eq, desc, and, isNull, gte, sql } from 'drizzle-orm';
import { formatDuration } from '../../lib/formatTime'; import { formatDuration } from '../../lib/formatTime';
@@ -87,11 +88,11 @@ if (currentOrg) {
stats.recentEntries = await db.select({ stats.recentEntries = await db.select({
entry: timeEntries, entry: timeEntries,
client: clients, client: clients,
category: categories, tag: tags,
}) })
.from(timeEntries) .from(timeEntries)
.innerJoin(clients, eq(timeEntries.clientId, clients.id)) .innerJoin(clients, eq(timeEntries.clientId, clients.id))
.innerJoin(categories, eq(timeEntries.categoryId, categories.id)) .leftJoin(tags, eq(timeEntries.tagId, tags.id))
.where(eq(timeEntries.organizationId, currentOrg.organizationId)) .where(eq(timeEntries.organizationId, currentOrg.organizationId))
.orderBy(desc(timeEntries.startTime)) .orderBy(desc(timeEntries.startTime))
.limit(5) .limit(5)
@@ -103,25 +104,25 @@ const hasMembership = userOrgs.length > 0;
--- ---
<DashboardLayout title="Dashboard - Chronus"> <DashboardLayout title="Dashboard - Chronus">
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 sm:gap-0 mb-8"> <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 sm:gap-0 mb-6">
<div> <div>
<h1 class="text-4xl font-bold text-primary mb-2"> <h1 class="text-2xl font-extrabold tracking-tight">
Dashboard Dashboard
</h1> </h1>
<p class="text-base-content/60">Welcome back, {user.name}!</p> <p class="text-base-content/60 text-sm mt-1">Welcome back, {user.name}!</p>
</div> </div>
<a href="/dashboard/organizations/new" class="btn btn-outline"> <a href="/dashboard/organizations/new" class="btn btn-ghost btn-sm">
<Icon name="heroicons:plus" class="w-5 h-5" /> <Icon name="heroicons:plus" class="w-4 h-4" />
New Team New Team
</a> </a>
</div> </div>
{!hasMembership && ( {!hasMembership && (
<div class="alert alert-info mb-8"> <div class="alert alert-info mb-6 text-sm">
<Icon name="heroicons:information-circle" class="w-6 h-6" /> <Icon name="heroicons:information-circle" class="w-5 h-5" />
<div> <div>
<h3 class="font-bold">Welcome to Chronus!</h3> <h3 class="font-bold">Welcome to Chronus!</h3>
<div class="text-sm">You're not part of any team yet. Create one or wait for an invitation.</div> <div class="text-xs">You're not part of any team yet. Create one or wait for an invitation.</div>
</div> </div>
<a href="/dashboard/organizations/new" class="btn btn-primary btn-sm"> <a href="/dashboard/organizations/new" class="btn btn-primary btn-sm">
<Icon name="heroicons:plus" class="w-4 h-4" /> <Icon name="heroicons:plus" class="w-4 h-4" />
@@ -133,63 +134,56 @@ const hasMembership = userOrgs.length > 0;
{hasMembership && ( {hasMembership && (
<> <>
<!-- Stats Overview --> <!-- Stats Overview -->
<div class="stats stats-vertical lg:stats-horizontal shadow-lg w-full mb-8"> <div class="grid grid-cols-2 lg:grid-cols-4 gap-3 mb-6">
<div class="stat"> <StatCard
<div class="stat-figure text-primary"> title="This Week"
<Icon name="heroicons:clock" class="w-8 h-8" /> value={formatDuration(stats.totalTimeThisWeek)}
</div> description="Total tracked time"
<div class="stat-title">This Week</div> icon="heroicons:clock"
<div class="stat-value text-primary text-3xl">{formatDuration(stats.totalTimeThisWeek)}</div> color="text-primary"
<div class="stat-desc">Total tracked time</div> />
</div> <StatCard
title="This Month"
<div class="stat"> value={formatDuration(stats.totalTimeThisMonth)}
<div class="stat-figure text-secondary"> description="Total tracked time"
<Icon name="heroicons:calendar" class="w-8 h-8" /> icon="heroicons:calendar"
</div> color="text-secondary"
<div class="stat-title">This Month</div> />
<div class="stat-value text-secondary text-3xl">{formatDuration(stats.totalTimeThisMonth)}</div> <StatCard
<div class="stat-desc">Total tracked time</div> title="Active Timers"
</div> value={String(stats.activeTimers)}
description="Currently running"
<div class="stat"> icon="heroicons:play-circle"
<div class="stat-figure text-accent"> color="text-accent"
<Icon name="heroicons:play-circle" class="w-8 h-8" /> />
</div> <StatCard
<div class="stat-title">Active Timers</div> title="Clients"
<div class="stat-value text-accent text-3xl">{stats.activeTimers}</div> value={String(stats.totalClients)}
<div class="stat-desc">Currently running</div> description="Total active"
</div> icon="heroicons:building-office"
color="text-info"
<div class="stat"> />
<div class="stat-figure text-info">
<Icon name="heroicons:building-office" class="w-8 h-8" />
</div>
<div class="stat-title">Clients</div>
<div class="stat-value text-info text-3xl">{stats.totalClients}</div>
<div class="stat-desc">Total active</div>
</div>
</div> </div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6"> <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
<!-- Quick Actions --> <!-- Quick Actions -->
<div class="card bg-base-100 shadow-xl"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title"> <h2 class="text-sm font-semibold flex items-center gap-2">
<Icon name="heroicons:bolt" class="w-6 h-6 text-warning" /> <Icon name="heroicons:bolt" class="w-4 h-4 text-warning" />
Quick Actions Quick Actions
</h2> </h2>
<div class="flex flex-col gap-3 mt-4"> <div class="flex flex-col gap-2 mt-3">
<a href="/dashboard/tracker" class="btn btn-primary"> <a href="/dashboard/tracker" class="btn btn-primary btn-sm">
<Icon name="heroicons:play" class="w-5 h-5" /> <Icon name="heroicons:play" class="w-4 h-4" />
Start Timer Start Timer
</a> </a>
<a href="/dashboard/clients/new" class="btn btn-outline"> <a href="/dashboard/clients/new" class="btn btn-ghost btn-sm">
<Icon name="heroicons:plus" class="w-5 h-5" /> <Icon name="heroicons:plus" class="w-4 h-4" />
Add Client Add Client
</a> </a>
<a href="/dashboard/reports" class="btn btn-outline"> <a href="/dashboard/reports" class="btn btn-ghost btn-sm">
<Icon name="heroicons:chart-bar" class="w-5 h-5" /> <Icon name="heroicons:chart-bar" class="w-4 h-4" />
View Reports View Reports
</a> </a>
</div> </div>
@@ -197,27 +191,32 @@ const hasMembership = userOrgs.length > 0;
</div> </div>
<!-- Recent Activity --> <!-- Recent Activity -->
<div class="card bg-base-100 shadow-xl"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title"> <h2 class="text-sm font-semibold flex items-center gap-2">
<Icon name="heroicons:clock" class="w-6 h-6 text-success" /> <Icon name="heroicons:clock" class="w-4 h-4 text-success" />
Recent Activity Recent Activity
</h2> </h2>
{stats.recentEntries.length > 0 ? ( {stats.recentEntries.length > 0 ? (
<ul class="space-y-3 mt-4"> <ul class="space-y-2 mt-3">
{stats.recentEntries.map(({ entry, client, category }) => ( {stats.recentEntries.map(({ entry, client, tag }) => (
<li class="p-3 rounded-lg bg-base-200 border-l-4 hover:bg-base-300 transition-colors" style={`border-color: ${category.color || '#3b82f6'}`}> <li class="p-2.5 rounded-lg bg-base-200/50 border-l-3 hover:bg-base-200 transition-colors" style={`border-color: ${tag?.color || 'oklch(var(--p))'}`}>
<div class="font-semibold text-sm">{client.name}</div> <div class="font-medium text-sm">{client.name}</div>
<div class="text-xs text-base-content/60 mt-1"> <div class="text-xs text-base-content/50 mt-0.5 flex flex-wrap gap-2 items-center">
{category.name} • {entry.endTime ? formatDuration(entry.endTime.getTime() - entry.startTime.getTime()) : 'Running...'} <span class="flex gap-1 flex-wrap">
{tag ? (
<span class="badge badge-xs badge-outline">{tag.name}</span>
) : <span class="italic opacity-50">No tag</span>}
</span>
<span>· {entry.endTime ? formatDuration(entry.endTime.getTime() - entry.startTime.getTime()) : 'Running...'}</span>
</div> </div>
</li> </li>
))} ))}
</ul> </ul>
) : ( ) : (
<div class="flex flex-col items-center justify-center py-8 text-center mt-4"> <div class="flex flex-col items-center justify-center py-6 text-center mt-3">
<Icon name="heroicons:clock" class="w-12 h-12 text-base-content/20 mb-3" /> <Icon name="heroicons:clock" class="w-10 h-10 text-base-content/15 mb-2" />
<p class="text-base-content/60 text-sm">No recent time entries</p> <p class="text-base-content/40 text-sm">No recent time entries</p>
</div> </div>
)} )}
</div> </div>

View File

@@ -4,6 +4,7 @@ import { Icon } from 'astro-icon/components';
import { db } from '../../../db'; import { db } from '../../../db';
import { invoices, invoiceItems, clients, members, organizations } from '../../../db/schema'; import { invoices, invoiceItems, clients, members, organizations } from '../../../db/schema';
import { eq, and } from 'drizzle-orm'; import { eq, and } from 'drizzle-orm';
import { formatCurrency } from '../../../lib/formatTime';
const { id } = Astro.params; const { id } = Astro.params;
const user = Astro.locals.user; const user = Astro.locals.user;
@@ -49,13 +50,6 @@ const items = await db.select()
.where(eq(invoiceItems.invoiceId, invoice.id)) .where(eq(invoiceItems.invoiceId, invoice.id))
.all(); .all();
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: invoice.currency,
}).format(amount / 100);
};
const isDraft = invoice.status === 'draft'; const isDraft = invoice.status === 'draft';
--- ---
@@ -68,7 +62,7 @@ const isDraft = invoice.status === 'draft';
<a href="/dashboard/invoices" class="btn btn-ghost btn-xs btn-square"> <a href="/dashboard/invoices" class="btn btn-ghost btn-xs btn-square">
<Icon name="heroicons:arrow-left" class="w-4 h-4" /> <Icon name="heroicons:arrow-left" class="w-4 h-4" />
</a> </a>
<div class={`badge ${ <div class={`badge badge-xs ${
invoice.status === 'paid' || invoice.status === 'accepted' ? 'badge-success' : invoice.status === 'paid' || invoice.status === 'accepted' ? 'badge-success' :
invoice.status === 'sent' ? 'badge-info' : invoice.status === 'sent' ? 'badge-info' :
invoice.status === 'void' || invoice.status === 'declined' ? 'badge-error' : invoice.status === 'void' || invoice.status === 'declined' ? 'badge-error' :
@@ -77,15 +71,15 @@ const isDraft = invoice.status === 'draft';
{invoice.status} {invoice.status}
</div> </div>
</div> </div>
<h1 class="text-3xl font-bold">{invoice.number}</h1> <h1 class="text-2xl font-extrabold tracking-tight">{invoice.number}</h1>
</div> </div>
<div class="flex gap-2"> <div class="flex gap-2">
{isDraft && ( {isDraft && (
<form method="POST" action={`/api/invoices/${invoice.id}/status`}> <form method="POST" action={`/api/invoices/${invoice.id}/status`}>
<input type="hidden" name="status" value="sent" /> <input type="hidden" name="status" value="sent" />
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary btn-sm">
<Icon name="heroicons:paper-airplane" class="w-5 h-5" /> <Icon name="heroicons:paper-airplane" class="w-4 h-4" />
Mark Sent Mark Sent
</button> </button>
</form> </form>
@@ -93,8 +87,8 @@ const isDraft = invoice.status === 'draft';
{(invoice.status !== 'paid' && invoice.status !== 'void' && invoice.type === 'invoice') && ( {(invoice.status !== 'paid' && invoice.status !== 'void' && invoice.type === 'invoice') && (
<form method="POST" action={`/api/invoices/${invoice.id}/status`}> <form method="POST" action={`/api/invoices/${invoice.id}/status`}>
<input type="hidden" name="status" value="paid" /> <input type="hidden" name="status" value="paid" />
<button type="submit" class="btn btn-success"> <button type="submit" class="btn btn-success btn-sm">
<Icon name="heroicons:check" class="w-5 h-5" /> <Icon name="heroicons:check" class="w-4 h-4" />
Mark Paid Mark Paid
</button> </button>
</form> </form>
@@ -102,25 +96,25 @@ const isDraft = invoice.status === 'draft';
{(invoice.status !== 'accepted' && invoice.status !== 'declined' && invoice.status !== 'void' && invoice.type === 'quote') && ( {(invoice.status !== 'accepted' && invoice.status !== 'declined' && invoice.status !== 'void' && invoice.type === 'quote') && (
<form method="POST" action={`/api/invoices/${invoice.id}/status`}> <form method="POST" action={`/api/invoices/${invoice.id}/status`}>
<input type="hidden" name="status" value="accepted" /> <input type="hidden" name="status" value="accepted" />
<button type="submit" class="btn btn-success"> <button type="submit" class="btn btn-success btn-sm">
<Icon name="heroicons:check" class="w-5 h-5" /> <Icon name="heroicons:check" class="w-4 h-4" />
Mark Accepted Mark Accepted
</button> </button>
</form> </form>
)} )}
{(invoice.type === 'quote' && invoice.status === 'accepted') && ( {(invoice.type === 'quote' && invoice.status === 'accepted') && (
<form method="POST" action={`/api/invoices/${invoice.id}/convert`}> <form method="POST" action={`/api/invoices/${invoice.id}/convert`}>
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary btn-sm">
<Icon name="heroicons:document-duplicate" class="w-5 h-5" /> <Icon name="heroicons:document-duplicate" class="w-4 h-4" />
Convert to Invoice Convert to Invoice
</button> </button>
</form> </form>
)} )}
<div class="dropdown dropdown-end"> <div class="dropdown dropdown-end">
<div role="button" tabindex="0" class="btn btn-square btn-ghost border border-base-300"> <div role="button" tabindex="0" class="btn btn-square btn-ghost btn-sm border border-base-200">
<Icon name="heroicons:ellipsis-horizontal" class="w-6 h-6" /> <Icon name="heroicons:ellipsis-horizontal" class="w-4 h-4" />
</div> </div>
<ul tabindex="0" class="dropdown-content z-1 menu p-2 shadow bg-base-100 rounded-box w-52 border border-base-200"> <ul tabindex="0" class="dropdown-content z-1 menu p-2 bg-base-100 rounded-box w-52 border border-base-200">
<li> <li>
<a href={`/dashboard/invoices/${invoice.id}/edit`}> <a href={`/dashboard/invoices/${invoice.id}/edit`}>
<Icon name="heroicons:pencil-square" class="w-4 h-4" /> <Icon name="heroicons:pencil-square" class="w-4 h-4" />
@@ -159,7 +153,7 @@ const isDraft = invoice.status === 'draft';
</div> </div>
<!-- Invoice Paper --> <!-- Invoice Paper -->
<div class="card bg-base-100 shadow-xl border border-base-200 print:shadow-none print:border-none"> <div class="card card-border bg-base-100 print:shadow-none print:border-none">
<div class="card-body p-8 sm:p-12"> <div class="card-body p-8 sm:p-12">
<!-- Header Section --> <!-- Header Section -->
<div class="flex flex-col sm:flex-row justify-between gap-8 mb-12"> <div class="flex flex-col sm:flex-row justify-between gap-8 mb-12">
@@ -235,8 +229,8 @@ const isDraft = invoice.status === 'draft';
<tr> <tr>
<td class="py-4">{item.description}</td> <td class="py-4">{item.description}</td>
<td class="py-4 text-right">{item.quantity}</td> <td class="py-4 text-right">{item.quantity}</td>
<td class="py-4 text-right">{formatCurrency(item.unitPrice)}</td> <td class="py-4 text-right">{formatCurrency(item.unitPrice, invoice.currency)}</td>
<td class="py-4 text-right font-medium">{formatCurrency(item.amount)}</td> <td class="py-4 text-right font-medium">{formatCurrency(item.amount, invoice.currency)}</td>
{isDraft && ( {isDraft && (
<td class="py-4 text-right"> <td class="py-4 text-right">
<form method="POST" action={`/api/invoices/${invoice.id}/items/delete`}> <form method="POST" action={`/api/invoices/${invoice.id}/items/delete`}>
@@ -263,20 +257,27 @@ const isDraft = invoice.status === 'draft';
<!-- Add Item Form (Only if Draft) --> <!-- Add Item Form (Only if Draft) -->
{isDraft && ( {isDraft && (
<form method="POST" action={`/api/invoices/${invoice.id}/items/add`} class="bg-base-200/50 p-4 rounded-lg mb-8 border border-base-300/50"> <div class="flex justify-end mb-4">
<h4 class="text-sm font-bold mb-3">Add Item</h4> <button onclick="document.getElementById('import_time_modal').showModal()" class="btn btn-sm btn-outline gap-2">
<div class="grid grid-cols-1 sm:grid-cols-12 gap-4 items-end"> <Icon name="heroicons:clock" class="w-4 h-4" />
Import Time
</button>
</div>
<form method="POST" action={`/api/invoices/${invoice.id}/items/add`} class="bg-base-200/50 p-4 rounded-lg mb-8 border border-base-200">
<h4 class="text-xs font-semibold mb-3">Add Item</h4>
<div class="grid grid-cols-1 sm:grid-cols-12 gap-3 items-end">
<div class="sm:col-span-6"> <div class="sm:col-span-6">
<label class="label label-text text-xs pt-0">Description</label> <label class="text-xs text-base-content/60" for="item-description">Description</label>
<input type="text" name="description" class="input input-sm input-bordered w-full" required placeholder="Service or product..." /> <input type="text" id="item-description" name="description" class="input input-sm w-full" required placeholder="Service or product..." />
</div> </div>
<div class="sm:col-span-2"> <div class="sm:col-span-2">
<label class="label label-text text-xs pt-0">Qty</label> <label class="text-xs text-base-content/60" for="item-quantity">Qty</label>
<input type="number" name="quantity" step="0.01" class="input input-sm input-bordered w-full" required value="1" /> <input type="number" id="item-quantity" name="quantity" step="0.01" class="input input-sm w-full" required value="1" />
</div> </div>
<div class="sm:col-span-3"> <div class="sm:col-span-3">
<label class="label label-text text-xs pt-0">Unit Price ({invoice.currency})</label> <label class="text-xs text-base-content/60" for="item-unit-price">Unit Price ({invoice.currency})</label>
<input type="number" name="unitPrice" step="0.01" class="input input-sm input-bordered w-full" required placeholder="0.00" /> <input type="number" id="item-unit-price" name="unitPrice" step="0.01" class="input input-sm w-full" required placeholder="0.00" />
</div> </div>
<div class="sm:col-span-1"> <div class="sm:col-span-1">
<button type="submit" class="btn btn-sm btn-primary w-full"> <button type="submit" class="btn btn-sm btn-primary w-full">
@@ -292,7 +293,7 @@ const isDraft = invoice.status === 'draft';
<div class="w-64 space-y-3"> <div class="w-64 space-y-3">
<div class="flex justify-between text-sm"> <div class="flex justify-between text-sm">
<span class="text-base-content/60">Subtotal</span> <span class="text-base-content/60">Subtotal</span>
<span class="font-medium">{formatCurrency(invoice.subtotal)}</span> <span class="font-medium">{formatCurrency(invoice.subtotal, invoice.currency)}</span>
</div> </div>
{(invoice.discountAmount && invoice.discountAmount > 0) && ( {(invoice.discountAmount && invoice.discountAmount > 0) && (
<div class="flex justify-between text-sm"> <div class="flex justify-between text-sm">
@@ -300,7 +301,7 @@ const isDraft = invoice.status === 'draft';
Discount Discount
{invoice.discountType === 'percentage' && ` (${invoice.discountValue}%)`} {invoice.discountType === 'percentage' && ` (${invoice.discountValue}%)`}
</span> </span>
<span class="font-medium text-success">-{formatCurrency(invoice.discountAmount)}</span> <span class="font-medium text-success">-{formatCurrency(invoice.discountAmount, invoice.currency)}</span>
</div> </div>
)} )}
{((invoice.taxRate ?? 0) > 0 || isDraft) && ( {((invoice.taxRate ?? 0) > 0 || isDraft) && (
@@ -313,13 +314,13 @@ const isDraft = invoice.status === 'draft';
</button> </button>
)} )}
</span> </span>
<span class="font-medium">{formatCurrency(invoice.taxAmount)}</span> <span class="font-medium">{formatCurrency(invoice.taxAmount, invoice.currency)}</span>
</div> </div>
)} )}
<div class="divider my-2"></div> <div class="divider my-2"></div>
<div class="flex justify-between text-lg font-bold"> <div class="flex justify-between text-lg font-bold">
<span>Total</span> <span>Total</span>
<span class="text-primary">{formatCurrency(invoice.total)}</span> <span class="text-primary">{formatCurrency(invoice.total, invoice.currency)}</span>
</div> </div>
</div> </div>
</div> </div>
@@ -345,27 +346,59 @@ const isDraft = invoice.status === 'draft';
<!-- Tax Modal --> <!-- Tax Modal -->
<dialog id="tax_modal" class="modal"> <dialog id="tax_modal" class="modal">
<div class="modal-box"> <div class="modal-box">
<h3 class="font-bold text-lg">Update Tax Rate</h3> <h3 class="font-semibold text-base">Update Tax Rate</h3>
<p class="py-4">Enter the tax percentage to apply to the subtotal.</p> <p class="py-3 text-sm text-base-content/60">Enter the tax percentage to apply to the subtotal.</p>
<form method="POST" action={`/api/invoices/${invoice.id}/update-tax`}> <form method="POST" action={`/api/invoices/${invoice.id}/update-tax`}>
<div class="form-control mb-6"> <fieldset class="fieldset mb-4">
<label class="label"> <legend class="fieldset-legend text-xs">Tax Rate (%)</legend>
<span class="label-text">Tax Rate (%)</span>
</label>
<input <input
type="number" type="number"
id="tax-rate"
name="taxRate" name="taxRate"
step="0.01" step="0.01"
min="0" min="0"
max="100" max="100"
class="input input-bordered w-full" class="input w-full"
value={invoice.taxRate ?? 0} value={invoice.taxRate ?? 0}
required required
/> />
</div> </fieldset>
<div class="modal-action"> <div class="modal-action">
<button type="button" class="btn" onclick="document.getElementById('tax_modal').close()">Cancel</button> <button type="button" class="btn btn-sm" onclick="document.getElementById('tax_modal').close()">Cancel</button>
<button type="submit" class="btn btn-primary">Update</button> <button type="submit" class="btn btn-primary btn-sm">Update</button>
</div>
</form>
</div>
<form method="dialog" class="modal-backdrop">
<button>close</button>
</form>
</dialog>
<!-- Import Time Modal -->
<dialog id="import_time_modal" class="modal">
<div class="modal-box">
<h3 class="font-semibold text-base">Import Time Entries</h3>
<p class="py-3 text-sm text-base-content/60">Import billable time entries for this client.</p>
<form method="POST" action={`/api/invoices/${invoice.id}/import-time`}>
<div class="grid grid-cols-2 gap-3 mb-3">
<fieldset class="fieldset">
<legend class="fieldset-legend text-xs">Start Date</legend>
<input type="date" id="start-date" name="startDate" class="input" required />
</fieldset>
<fieldset class="fieldset">
<legend class="fieldset-legend text-xs">End Date</legend>
<input type="date" id="end-date" name="endDate" class="input" required />
</fieldset>
</div>
<label class="label cursor-pointer justify-start gap-3 mb-4">
<input type="checkbox" name="groupByDay" class="checkbox checkbox-sm" />
<span class="text-sm">Group entries by day</span>
</label>
<div class="modal-action">
<button type="button" class="btn btn-sm" onclick="document.getElementById('import_time_modal').close()">Cancel</button>
<button type="submit" class="btn btn-primary btn-sm">Import</button>
</div> </div>
</form> </form>
</div> </div>

View File

@@ -47,130 +47,120 @@ const discountValueDisplay = invoice.discountType === 'fixed'
<DashboardLayout title={`Edit ${invoice.number} - Chronus`}> <DashboardLayout title={`Edit ${invoice.number} - Chronus`}>
<div class="max-w-3xl mx-auto"> <div class="max-w-3xl mx-auto">
<div class="mb-6"> <div class="mb-6">
<a href={`/dashboard/invoices/${invoice.id}`} class="btn btn-ghost btn-sm gap-2 pl-0 hover:bg-transparent text-base-content/60"> <a href={`/dashboard/invoices/${invoice.id}`} class="btn btn-ghost btn-xs gap-2 pl-0 hover:bg-transparent text-base-content/60">
<Icon name="heroicons:arrow-left" class="w-4 h-4" /> <Icon name="heroicons:arrow-left" class="w-4 h-4" />
Back to Invoice Back to Invoice
</a> </a>
<h1 class="text-3xl font-bold mt-2">Edit Details</h1> <h1 class="text-2xl font-extrabold tracking-tight mt-2">Edit Details</h1>
</div> </div>
<form method="POST" action={`/api/invoices/${invoice.id}/update`} class="card bg-base-100 shadow-xl border border-base-200"> <form method="POST" action={`/api/invoices/${invoice.id}/update`} class="card card-border bg-base-100">
<div class="card-body gap-6"> <div class="card-body p-4 gap-3">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<!-- Number --> <!-- Number -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Number</legend>
<span class="label-text font-semibold">Number</span>
</label>
<input <input
type="text" type="text"
id="invoice-number"
name="number" name="number"
class="input input-bordered font-mono" class="input font-mono"
value={invoice.number} value={invoice.number}
required required
/> />
</div> </fieldset>
<!-- Currency --> <!-- Currency -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Currency</legend>
<span class="label-text font-semibold">Currency</span> <select id="invoice-currency" name="currency" class="select w-full">
</label>
<select name="currency" class="select select-bordered w-full">
<option value="USD" selected={invoice.currency === 'USD'}>USD ($)</option> <option value="USD" selected={invoice.currency === 'USD'}>USD ($)</option>
<option value="EUR" selected={invoice.currency === 'EUR'}>EUR (€)</option> <option value="EUR" selected={invoice.currency === 'EUR'}>EUR (€)</option>
<option value="GBP" selected={invoice.currency === 'GBP'}>GBP (£)</option> <option value="GBP" selected={invoice.currency === 'GBP'}>GBP (£)</option>
<option value="CAD" selected={invoice.currency === 'CAD'}>CAD ($)</option> <option value="CAD" selected={invoice.currency === 'CAD'}>CAD ($)</option>
<option value="AUD" selected={invoice.currency === 'AUD'}>AUD ($)</option> <option value="AUD" selected={invoice.currency === 'AUD'}>AUD ($)</option>
</select> </select>
</div> </fieldset>
<!-- Issue Date --> <!-- Issue Date -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Issue Date</legend>
<span class="label-text font-semibold">Issue Date</span>
</label>
<input <input
type="date" type="date"
id="invoice-issue-date"
name="issueDate" name="issueDate"
class="input input-bordered" class="input"
value={issueDateStr} value={issueDateStr}
required required
/> />
</div> </fieldset>
<!-- Due Date --> <!-- Due Date -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">{invoice.type === 'quote' ? 'Valid Until' : 'Due Date'}</legend>
<span class="label-text font-semibold">
{invoice.type === 'quote' ? 'Valid Until' : 'Due Date'}
</span>
</label>
<input <input
type="date" type="date"
id="invoice-due-date"
name="dueDate" name="dueDate"
class="input input-bordered" class="input"
value={dueDateStr} value={dueDateStr}
required required
/> />
</div> </fieldset>
<!-- Discount --> <!-- Discount -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Discount</legend>
<span class="label-text font-semibold">Discount</span>
</label>
<div class="join w-full"> <div class="join w-full">
<select name="discountType" class="select select-bordered join-item"> <select id="invoice-discount-type" name="discountType" class="select join-item">
<option value="percentage" selected={!invoice.discountType || invoice.discountType === 'percentage'}>%</option> <option value="percentage" selected={!invoice.discountType || invoice.discountType === 'percentage'}>%</option>
<option value="fixed" selected={invoice.discountType === 'fixed'}>Fixed</option> <option value="fixed" selected={invoice.discountType === 'fixed'}>Fixed</option>
</select> </select>
<input <input
type="number" type="number"
id="invoice-discount-value"
name="discountValue" name="discountValue"
step="0.01" step="0.01"
min="0" min="0"
class="input input-bordered join-item w-full" class="input join-item w-full"
value={discountValueDisplay} value={discountValueDisplay}
/> />
</div> </div>
</div> </fieldset>
<!-- Tax Rate --> <!-- Tax Rate -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Tax Rate (%)</legend>
<span class="label-text font-semibold">Tax Rate (%)</span>
</label>
<input <input
type="number" type="number"
id="invoice-tax-rate"
name="taxRate" name="taxRate"
step="0.01" step="0.01"
min="0" min="0"
max="100" max="100"
class="input input-bordered" class="input"
value={invoice.taxRate} value={invoice.taxRate}
/> />
</div> </fieldset>
</div> </div>
<!-- Notes --> <!-- Notes -->
<div class="form-control flex flex-col"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Notes / Terms</legend>
<span class="label-text font-semibold">Notes / Terms</span>
</label>
<textarea <textarea
id="invoice-notes"
name="notes" name="notes"
class="textarea textarea-bordered h-32 font-mono text-sm" class="textarea h-32 font-mono text-sm"
placeholder="Payment terms, bank details, or thank you notes..." placeholder="Payment terms, bank details, or thank you notes..."
>{invoice.notes}</textarea> >{invoice.notes}</textarea>
</div> </fieldset>
<div class="divider"></div> <div class="divider my-0"></div>
<div class="card-actions justify-end"> <div class="flex justify-end gap-2">
<a href={`/dashboard/invoices/${invoice.id}`} class="btn btn-ghost">Cancel</a> <a href={`/dashboard/invoices/${invoice.id}`} class="btn btn-ghost btn-sm">Cancel</a>
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary btn-sm">
Save Changes Save Changes
</button> </button>
</div> </div>

View File

@@ -1,47 +1,92 @@
--- ---
import DashboardLayout from '../../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components'; import { Icon } from 'astro-icon/components';
import StatCard from '../../../components/StatCard.astro';
import { db } from '../../../db'; import { db } from '../../../db';
import { invoices, clients, members } from '../../../db/schema'; import { invoices, clients } from '../../../db/schema';
import { eq, desc, and } from 'drizzle-orm'; import { eq, desc, and, gte, lte, sql } from 'drizzle-orm';
import { getCurrentTeam } from '../../../lib/getCurrentTeam';
import { formatCurrency } from '../../../lib/formatTime';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const currentTeamIdResolved = userMembership.organizationId; const currentTeamIdResolved = userMembership.organizationId;
// Fetch invoices and quotes // Get filter parameters
const allInvoices = await db.select({ const currentYear = new Date().getFullYear();
const yearParam = Astro.url.searchParams.get('year');
const selectedYear: string | number = yearParam === 'current' || !yearParam ? 'current' : parseInt(yearParam);
const yearNum = typeof selectedYear === 'number' ? selectedYear : currentYear;
const selectedType = Astro.url.searchParams.get('type') || 'all';
const selectedStatus = Astro.url.searchParams.get('status') || 'all';
const sortBy = Astro.url.searchParams.get('sort') || 'date-desc';
// Fetch all invoices for the organization (for year dropdown)
const allInvoicesRaw = await db.select({
invoice: invoices, invoice: invoices,
client: clients, client: clients,
}) })
.from(invoices) .from(invoices)
.leftJoin(clients, eq(invoices.clientId, clients.id)) .leftJoin(clients, eq(invoices.clientId, clients.id))
.where(eq(invoices.organizationId, currentTeamIdResolved)) .where(eq(invoices.organizationId, currentTeamIdResolved))
.orderBy(desc(invoices.issueDate))
.all(); .all();
const formatCurrency = (amount: number, currency: string) => { // Get unique years from invoices
return new Intl.NumberFormat('en-US', { const availableYears = [...new Set(allInvoicesRaw.map(i => i.invoice.issueDate.getFullYear()))].sort((a, b) => b - a);
style: 'currency',
currency: currency, // Ensure current year is in the list
}).format(amount / 100); if (!availableYears.includes(currentYear)) {
}; availableYears.unshift(currentYear);
}
// Filter by year
const yearStart = new Date(yearNum, 0, 1);
const yearEnd = selectedYear === 'current' ? new Date() : new Date(yearNum, 11, 31, 23, 59, 59);
let filteredInvoices = allInvoicesRaw.filter(i => {
const issueDate = i.invoice.issueDate;
return issueDate >= yearStart && issueDate <= yearEnd;
});
// Filter by type
if (selectedType !== 'all') {
filteredInvoices = filteredInvoices.filter(i => i.invoice.type === selectedType);
}
// Filter by status
if (selectedStatus !== 'all') {
filteredInvoices = filteredInvoices.filter(i => i.invoice.status === selectedStatus);
}
// Sort invoices
const allInvoices = filteredInvoices.sort((a, b) => {
switch (sortBy) {
case 'date-desc':
return b.invoice.issueDate.getTime() - a.invoice.issueDate.getTime();
case 'date-asc':
return a.invoice.issueDate.getTime() - b.invoice.issueDate.getTime();
case 'amount-desc':
return b.invoice.total - a.invoice.total;
case 'amount-asc':
return a.invoice.total - b.invoice.total;
case 'number-desc':
return b.invoice.number.localeCompare(a.invoice.number);
case 'number-asc':
return a.invoice.number.localeCompare(b.invoice.number);
default:
return b.invoice.issueDate.getTime() - a.invoice.issueDate.getTime();
}
});
// Calculate stats for the selected year
const yearInvoices = allInvoicesRaw.filter(i => {
const issueDate = i.invoice.issueDate;
return issueDate >= yearStart && issueDate <= yearEnd;
});
const getStatusColor = (status: string) => { const getStatusColor = (status: string) => {
switch (status) { switch (status) {
@@ -59,60 +104,114 @@ const getStatusColor = (status: string) => {
<DashboardLayout title="Invoices & Quotes - Chronus"> <DashboardLayout title="Invoices & Quotes - Chronus">
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6"> <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6">
<div> <div>
<h1 class="text-3xl font-bold">Invoices & Quotes</h1> <h1 class="text-2xl font-extrabold tracking-tight">Invoices & Quotes</h1>
<p class="text-base-content/60 mt-1">Manage your billing and estimates</p> <p class="text-base-content/60 text-sm mt-1">Manage your billing and estimates</p>
</div> </div>
<a href="/dashboard/invoices/new" class="btn btn-primary"> <a href="/dashboard/invoices/new" class="btn btn-primary btn-sm">
<Icon name="heroicons:plus" class="w-5 h-5" /> <Icon name="heroicons:plus" class="w-4 h-4" />
Create New Create New
</a> </a>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8"> <div class="grid grid-cols-1 md:grid-cols-3 gap-3 mb-6">
<div class="stats shadow bg-base-100 border border-base-200"> <StatCard
<div class="stat"> title="Total Invoices"
<div class="stat-figure text-primary"> value={String(yearInvoices.filter(i => i.invoice.type === 'invoice').length)}
<Icon name="heroicons:document-text" class="w-8 h-8" /> description={selectedYear === 'current' ? `${currentYear} (YTD)` : String(selectedYear)}
</div> icon="heroicons:document-text"
<div class="stat-title">Total Invoices</div> color="text-primary"
<div class="stat-value text-primary">{allInvoices.filter(i => i.invoice.type === 'invoice').length}</div> />
<div class="stat-desc">All time</div> <StatCard
</div> title="Open Quotes"
</div> value={String(yearInvoices.filter(i => i.invoice.type === 'quote' && i.invoice.status === 'sent').length)}
description="Waiting for approval"
icon="heroicons:clipboard-document-list"
color="text-secondary"
/>
<StatCard
title="Total Revenue"
value={formatCurrency(yearInvoices
.filter(i => i.invoice.type === 'invoice' && i.invoice.status === 'paid')
.reduce((acc, curr) => acc + curr.invoice.total, 0), 'USD')}
description={`Paid invoices (${selectedYear === 'current' ? `${currentYear} YTD` : selectedYear})`}
icon="heroicons:currency-dollar"
color="text-success"
/>
</div>
<div class="stats shadow bg-base-100 border border-base-200"> <!-- Filters -->
<div class="stat"> <div class="card card-border bg-base-100 mb-6">
<div class="stat-figure text-secondary"> <div class="card-body p-4">
<Icon name="heroicons:clipboard-document-list" class="w-8 h-8" /> <form method="GET" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3">
</div> <fieldset class="fieldset">
<div class="stat-title">Open Quotes</div> <legend class="fieldset-legend text-xs">Year</legend>
<div class="stat-value text-secondary">{allInvoices.filter(i => i.invoice.type === 'quote' && i.invoice.status === 'sent').length}</div> <select name="year" class="select w-full" onchange="this.form.submit()">
<div class="stat-desc">Waiting for approval</div> <option value="current" selected={selectedYear === 'current'}>Current Year to Date ({currentYear})</option>
</div> {availableYears.map(year => (
</div> <option value={year} selected={year === selectedYear}>{year}</option>
))}
</select>
</fieldset>
<div class="stats shadow bg-base-100 border border-base-200"> <fieldset class="fieldset">
<div class="stat"> <legend class="fieldset-legend text-xs">Type</legend>
<div class="stat-figure text-success"> <select name="type" class="select w-full" onchange="this.form.submit()">
<Icon name="heroicons:currency-dollar" class="w-8 h-8" /> <option value="all" selected={selectedType === 'all'}>All Types</option>
<option value="invoice" selected={selectedType === 'invoice'}>Invoices</option>
<option value="quote" selected={selectedType === 'quote'}>Quotes</option>
</select>
</fieldset>
<fieldset class="fieldset">
<legend class="fieldset-legend text-xs">Status</legend>
<select name="status" class="select w-full" onchange="this.form.submit()">
<option value="all" selected={selectedStatus === 'all'}>All Statuses</option>
<option value="draft" selected={selectedStatus === 'draft'}>Draft</option>
<option value="sent" selected={selectedStatus === 'sent'}>Sent</option>
<option value="paid" selected={selectedStatus === 'paid'}>Paid</option>
<option value="accepted" selected={selectedStatus === 'accepted'}>Accepted</option>
<option value="declined" selected={selectedStatus === 'declined'}>Declined</option>
<option value="void" selected={selectedStatus === 'void'}>Void</option>
</select>
</fieldset>
<fieldset class="fieldset">
<legend class="fieldset-legend text-xs">Sort By</legend>
<select name="sort" class="select w-full" onchange="this.form.submit()">
<option value="date-desc" selected={sortBy === 'date-desc'}>Date (Newest First)</option>
<option value="date-asc" selected={sortBy === 'date-asc'}>Date (Oldest First)</option>
<option value="amount-desc" selected={sortBy === 'amount-desc'}>Amount (High to Low)</option>
<option value="amount-asc" selected={sortBy === 'amount-asc'}>Amount (Low to High)</option>
<option value="number-desc" selected={sortBy === 'number-desc'}>Number (Z-A)</option>
<option value="number-asc" selected={sortBy === 'number-asc'}>Number (A-Z)</option>
</select>
</fieldset>
</form>
{(selectedYear !== 'current' || selectedType !== 'all' || selectedStatus !== 'all' || sortBy !== 'date-desc') && (
<div class="mt-3">
<a href="/dashboard/invoices" class="btn btn-ghost btn-xs">
<Icon name="heroicons:x-mark" class="w-3 h-3" />
Clear Filters
</a>
</div> </div>
<div class="stat-title">Total Revenue</div> )}
<div class="stat-value text-success">
{formatCurrency(allInvoices
.filter(i => i.invoice.type === 'invoice' && i.invoice.status === 'paid')
.reduce((acc, curr) => acc + curr.invoice.total, 0), 'USD')}
</div>
<div class="stat-desc">Paid invoices</div>
</div>
</div> </div>
</div> </div>
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body p-0"> <div class="card-body p-0">
<div class="px-4 py-3 border-b border-base-200">
<p class="text-xs text-base-content/50">
Showing <span class="font-semibold text-base-content">{allInvoices.length}</span>
{allInvoices.length === 1 ? 'result' : 'results'}
{selectedYear === 'current' ? ` for ${currentYear} (year to date)` : ` for ${selectedYear}`}
</p>
</div>
<div class="overflow-x-auto md:overflow-visible pb-32 md:pb-0"> <div class="overflow-x-auto md:overflow-visible pb-32 md:pb-0">
<table class="table table-zebra"> <table class="table table-sm">
<thead> <thead>
<tr class="bg-base-200/50"> <tr>
<th>Number</th> <th>Number</th>
<th>Client</th> <th>Client</th>
<th>Date</th> <th>Date</th>
@@ -126,14 +225,14 @@ const getStatusColor = (status: string) => {
<tbody> <tbody>
{allInvoices.length === 0 ? ( {allInvoices.length === 0 ? (
<tr> <tr>
<td colspan="8" class="text-center py-8 text-base-content/60"> <td colspan="8" class="text-center py-8 text-base-content/50 text-sm">
No invoices or quotes found. Create one to get started. No invoices or quotes found. Create one to get started.
</td> </td>
</tr> </tr>
) : ( ) : (
allInvoices.map(({ invoice, client }) => ( allInvoices.map(({ invoice, client }) => (
<tr class="hover:bg-base-200/50 transition-colors"> <tr class="hover">
<td class="font-mono font-medium"> <td class="font-mono font-medium text-sm">
<a href={`/dashboard/invoices/${invoice.id}`} class="link link-hover text-primary"> <a href={`/dashboard/invoices/${invoice.id}`} class="link link-hover text-primary">
{invoice.number} {invoice.number}
</a> </a>
@@ -151,7 +250,7 @@ const getStatusColor = (status: string) => {
{formatCurrency(invoice.total, invoice.currency)} {formatCurrency(invoice.total, invoice.currency)}
</td> </td>
<td> <td>
<div class={`badge ${getStatusColor(invoice.status)} badge-sm uppercase font-bold tracking-wider`}> <div class={`badge ${getStatusColor(invoice.status)} badge-xs uppercase font-bold tracking-wider`}>
{invoice.status} {invoice.status}
</div> </div>
</td> </td>
@@ -160,10 +259,10 @@ const getStatusColor = (status: string) => {
</td> </td>
<td class="text-right"> <td class="text-right">
<div class="dropdown dropdown-end"> <div class="dropdown dropdown-end">
<div role="button" tabindex="0" class="btn btn-ghost btn-sm btn-square"> <div role="button" tabindex="0" class="btn btn-ghost btn-xs btn-square">
<Icon name="heroicons:ellipsis-vertical" class="w-5 h-5" /> <Icon name="heroicons:ellipsis-vertical" class="w-4 h-4" />
</div> </div>
<ul tabindex="0" class="dropdown-content menu p-2 shadow-lg bg-base-100 rounded-box w-52 border border-base-200 z-100"> <ul tabindex="0" class="dropdown-content menu p-2 bg-base-100 rounded-box w-52 border border-base-200 z-100">
<li> <li>
<a href={`/dashboard/invoices/${invoice.id}`}> <a href={`/dashboard/invoices/${invoice.id}`}>
<Icon name="heroicons:eye" class="w-4 h-4" /> <Icon name="heroicons:eye" class="w-4 h-4" />

View File

@@ -2,29 +2,23 @@
import DashboardLayout from '../../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components'; import { Icon } from 'astro-icon/components';
import { db } from '../../../db'; import { db } from '../../../db';
import { clients, members, invoices } from '../../../db/schema'; import { clients, invoices, organizations } from '../../../db/schema';
import { eq, desc, and } from 'drizzle-orm'; import { eq, desc, and } from 'drizzle-orm';
import { getCurrentTeam } from '../../../lib/getCurrentTeam';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const currentTeamIdResolved = userMembership.organizationId; const currentTeamIdResolved = userMembership.organizationId;
const currentOrganization = await db.select()
.from(organizations)
.where(eq(organizations.id, currentTeamIdResolved))
.get();
// Fetch clients for dropdown // Fetch clients for dropdown
const teamClients = await db.select() const teamClients = await db.select()
.from(clients) .from(clients)
@@ -86,122 +80,112 @@ const defaultDueDate = nextMonth.toISOString().split('T')[0];
<DashboardLayout title="New Document - Chronus"> <DashboardLayout title="New Document - Chronus">
<div class="max-w-3xl mx-auto"> <div class="max-w-3xl mx-auto">
<div class="mb-6"> <div class="mb-6">
<a href="/dashboard/invoices" class="btn btn-ghost btn-sm gap-2 pl-0 hover:bg-transparent text-base-content/60"> <a href="/dashboard/invoices" class="btn btn-ghost btn-xs gap-2 pl-0 hover:bg-transparent text-base-content/60">
<Icon name="heroicons:arrow-left" class="w-4 h-4" /> <Icon name="heroicons:arrow-left" class="w-4 h-4" />
Back to Invoices Back to Invoices
</a> </a>
<h1 class="text-3xl font-bold mt-2">Create New Document</h1> <h1 class="text-2xl font-extrabold tracking-tight mt-2">Create New Document</h1>
</div> </div>
{teamClients.length === 0 ? ( {teamClients.length === 0 ? (
<div role="alert" class="alert alert-warning shadow-lg"> <div role="alert" class="alert alert-warning">
<Icon name="heroicons:exclamation-triangle" class="w-6 h-6" /> <Icon name="heroicons:exclamation-triangle" class="w-5 h-5" />
<div> <div>
<h3 class="font-bold">No Clients Found</h3> <h3 class="font-semibold text-sm">No Clients Found</h3>
<div class="text-xs">You need to add a client before you can create an invoice or quote.</div> <div class="text-xs">You need to add a client before you can create an invoice or quote.</div>
</div> </div>
<a href="/dashboard/clients" class="btn btn-sm">Manage Clients</a> <a href="/dashboard/clients" class="btn btn-sm">Manage Clients</a>
</div> </div>
) : ( ) : (
<form method="POST" action="/api/invoices/create" class="card bg-base-100 shadow-xl border border-base-200"> <form method="POST" action="/api/invoices/create" class="card card-border bg-base-100">
<div class="card-body gap-6"> <div class="card-body p-4 gap-4">
<!-- Document Type --> <!-- Document Type -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Document Type</legend>
<span class="label-text font-semibold">Document Type</span> <div class="flex gap-3">
</label> <label class="label cursor-pointer justify-start gap-2 border border-base-200 rounded-lg p-3 flex-1 hover:border-primary has-checked:border-primary has-checked:bg-primary/5 transition-all font-medium text-sm" for="document-type-invoice">
<div class="flex gap-4"> <input type="radio" id="document-type-invoice" name="type" value="invoice" class="radio radio-primary radio-sm" checked />
<label class="label cursor-pointer justify-start gap-2 border border-base-300 rounded-lg p-3 flex-1 hover:border-primary has-checked:border-primary has-checked:bg-primary/5 transition-all"> Invoice
<input type="radio" name="type" value="invoice" class="radio radio-primary" checked />
<span class="label-text font-medium">Invoice</span>
</label> </label>
<label class="label cursor-pointer justify-start gap-2 border border-base-300 rounded-lg p-3 flex-1 hover:border-primary has-checked:border-primary has-checked:bg-primary/5 transition-all"> <label class="label cursor-pointer justify-start gap-2 border border-base-200 rounded-lg p-3 flex-1 hover:border-primary has-checked:border-primary has-checked:bg-primary/5 transition-all font-medium text-sm" for="document-type-quote">
<input type="radio" name="type" value="quote" class="radio radio-primary" /> <input type="radio" id="document-type-quote" name="type" value="quote" class="radio radio-primary radio-sm" />
<span class="label-text font-medium">Quote / Estimate</span> Quote / Estimate
</label> </label>
</div> </div>
</div> </fieldset>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<!-- Client --> <!-- Client -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Client</legend>
<span class="label-text font-semibold">Client</span> <select id="invoice-client" name="clientId" class="select w-full" required>
</label>
<select name="clientId" class="select select-bordered w-full" required>
<option value="" disabled selected>Select a client...</option> <option value="" disabled selected>Select a client...</option>
{teamClients.map(client => ( {teamClients.map(client => (
<option value={client.id}>{client.name}</option> <option value={client.id}>{client.name}</option>
))} ))}
</select> </select>
</div> </fieldset>
<!-- Number --> <!-- Number -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Number</legend>
<span class="label-text font-semibold">Number</span>
</label>
<input <input
type="text" type="text"
name="number" name="number"
id="documentNumber" id="documentNumber"
class="input input-bordered font-mono" class="input font-mono"
value={nextInvoiceNumber} value={nextInvoiceNumber}
data-invoice-number={nextInvoiceNumber} data-invoice-number={nextInvoiceNumber}
data-quote-number={nextQuoteNumber} data-quote-number={nextQuoteNumber}
required required
/> />
</div> </fieldset>
<!-- Issue Date --> <!-- Issue Date -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Issue Date</legend>
<span class="label-text font-semibold">Issue Date</span>
</label>
<input <input
type="date" type="date"
id="invoice-issue-date"
name="issueDate" name="issueDate"
class="input input-bordered" class="input"
value={today} value={today}
required required
/> />
</div> </fieldset>
<!-- Due Date --> <!-- Due Date -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs" id="dueDateLabel">Due Date</legend>
<span class="label-text font-semibold" id="dueDateLabel">Due Date</span>
</label>
<input <input
type="date" type="date"
id="invoice-due-date"
name="dueDate" name="dueDate"
class="input input-bordered" class="input"
value={defaultDueDate} value={defaultDueDate}
required required
/> />
</div> </fieldset>
<!-- Currency --> <!-- Currency -->
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Currency</legend>
<span class="label-text font-semibold">Currency</span> <select id="invoice-currency" name="currency" class="select w-full">
</label> <option value="USD" selected={currentOrganization?.defaultCurrency === 'USD'}>USD ($)</option>
<select name="currency" class="select select-bordered w-full"> <option value="EUR" selected={currentOrganization?.defaultCurrency === 'EUR'}>EUR (€)</option>
<option value="USD">USD ($)</option> <option value="GBP" selected={currentOrganization?.defaultCurrency === 'GBP'}>GBP (£)</option>
<option value="EUR">EUR ()</option> <option value="CAD" selected={currentOrganization?.defaultCurrency === 'CAD'}>CAD ($)</option>
<option value="GBP">GBP (£)</option> <option value="AUD" selected={currentOrganization?.defaultCurrency === 'AUD'}>AUD ($)</option>
<option value="CAD">CAD ($)</option>
<option value="AUD">AUD ($)</option>
</select> </select>
</div> </fieldset>
</div> </div>
<div class="divider"></div> <div class="divider my-0"></div>
<div class="card-actions justify-end"> <div class="flex justify-end gap-2">
<a href="/dashboard/invoices" class="btn btn-ghost">Cancel</a> <a href="/dashboard/invoices" class="btn btn-ghost btn-sm">Cancel</a>
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary btn-sm">
Create Draft Create Draft
<Icon name="heroicons:arrow-right" class="w-4 h-4" /> <Icon name="heroicons:arrow-right" class="w-4 h-4" />
</button> </button>

View File

@@ -12,36 +12,34 @@ if (!user) return Astro.redirect('/login');
<DashboardLayout title="Create Team - Chronus"> <DashboardLayout title="Create Team - Chronus">
<div class="max-w-2xl mx-auto"> <div class="max-w-2xl mx-auto">
<div class="flex items-center gap-3 mb-6"> <div class="flex items-center gap-3 mb-6">
<a href="/dashboard" class="btn btn-ghost btn-sm"> <a href="/dashboard" class="btn btn-ghost btn-xs">
<Icon name="heroicons:arrow-left" class="w-5 h-5" /> <Icon name="heroicons:arrow-left" class="w-4 h-4" />
</a> </a>
<h1 class="text-3xl font-bold">Create New Team</h1> <h1 class="text-2xl font-extrabold tracking-tight">Create New Team</h1>
</div> </div>
<form method="POST" action="/api/organizations/create" class="card bg-base-200 shadow-xl border border-base-300"> <form method="POST" action="/api/organizations/create" class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<div class="alert alert-info mb-4"> <div class="alert alert-info mb-4">
<Icon name="heroicons:information-circle" class="w-6 h-6" /> <Icon name="heroicons:information-circle" class="w-4 h-4" />
<span>Create a new team to manage separate projects and collaborators. You'll be the owner.</span> <span class="text-sm">Create a new team to manage separate projects and collaborators. You'll be the owner.</span>
</div> </div>
<div class="form-control"> <fieldset class="fieldset">
<label class="label pb-2" for="name"> <legend class="fieldset-legend text-xs">Team Name</legend>
<span class="label-text font-medium">Team Name</span>
</label>
<input <input
type="text" type="text"
id="name" id="name"
name="name" name="name"
placeholder="Acme Corp" placeholder="Acme Corp"
class="input input-bordered w-full" class="input w-full"
required required
/> />
</div> </fieldset>
<div class="card-actions justify-end mt-6"> <div class="flex justify-end gap-2 mt-4">
<a href="/dashboard" class="btn btn-ghost">Cancel</a> <a href="/dashboard" class="btn btn-ghost btn-sm">Cancel</a>
<button type="submit" class="btn btn-primary">Create Team</button> <button type="submit" class="btn btn-primary btn-sm">Create Team</button>
</div> </div>
</div> </div>
</form> </form>

View File

@@ -1,31 +1,21 @@
--- ---
import DashboardLayout from '../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components'; import { Icon } from 'astro-icon/components';
import CategoryChart from '../../components/CategoryChart.vue'; import StatCard from '../../components/StatCard.astro';
import TagChart from '../../components/TagChart.vue';
import ClientChart from '../../components/ClientChart.vue'; import ClientChart from '../../components/ClientChart.vue';
import MemberChart from '../../components/MemberChart.vue'; import MemberChart from '../../components/MemberChart.vue';
import { db } from '../../db'; import { db } from '../../db';
import { timeEntries, members, users, clients, categories, invoices } from '../../db/schema'; import { timeEntries, members, users, clients, tags, invoices } from '../../db/schema';
import { eq, and, gte, lte, sql, desc } from 'drizzle-orm'; import { eq, and, gte, lte, sql, desc } from 'drizzle-orm';
import { formatDuration, formatTimeRange } from '../../lib/formatTime'; import { formatDuration, formatTimeRange, formatCurrency } from '../../lib/formatTime';
import { getCurrentTeam } from '../../lib/getCurrentTeam';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const teamMembers = await db.select({ const teamMembers = await db.select({
id: users.id, id: users.id,
@@ -37,9 +27,9 @@ const teamMembers = await db.select({
.where(eq(members.organizationId, userMembership.organizationId)) .where(eq(members.organizationId, userMembership.organizationId))
.all(); .all();
const allCategories = await db.select() const allTags = await db.select()
.from(categories) .from(tags)
.where(eq(categories.organizationId, userMembership.organizationId)) .where(eq(tags.organizationId, userMembership.organizationId))
.all(); .all();
const allClients = await db.select() const allClients = await db.select()
@@ -49,7 +39,7 @@ const allClients = await db.select()
const url = new URL(Astro.request.url); const url = new URL(Astro.request.url);
const selectedMemberId = url.searchParams.get('member') || ''; const selectedMemberId = url.searchParams.get('member') || '';
const selectedCategoryId = url.searchParams.get('category') || ''; const selectedTagId = url.searchParams.get('tag') || '';
const selectedClientId = url.searchParams.get('client') || ''; const selectedClientId = url.searchParams.get('client') || '';
const timeRange = url.searchParams.get('range') || 'week'; const timeRange = url.searchParams.get('range') || 'week';
const customFrom = url.searchParams.get('from'); const customFrom = url.searchParams.get('from');
@@ -102,8 +92,8 @@ if (selectedMemberId) {
conditions.push(eq(timeEntries.userId, selectedMemberId)); conditions.push(eq(timeEntries.userId, selectedMemberId));
} }
if (selectedCategoryId) { if (selectedTagId) {
conditions.push(eq(timeEntries.categoryId, selectedCategoryId)); conditions.push(eq(timeEntries.tagId, selectedTagId));
} }
if (selectedClientId) { if (selectedClientId) {
@@ -114,12 +104,12 @@ const entries = await db.select({
entry: timeEntries, entry: timeEntries,
user: users, user: users,
client: clients, client: clients,
category: categories, tag: tags,
}) })
.from(timeEntries) .from(timeEntries)
.innerJoin(users, eq(timeEntries.userId, users.id)) .innerJoin(users, eq(timeEntries.userId, users.id))
.innerJoin(clients, eq(timeEntries.clientId, clients.id)) .innerJoin(clients, eq(timeEntries.clientId, clients.id))
.innerJoin(categories, eq(timeEntries.categoryId, categories.id)) .leftJoin(tags, eq(timeEntries.tagId, tags.id))
.where(and(...conditions)) .where(and(...conditions))
.orderBy(desc(timeEntries.startTime)) .orderBy(desc(timeEntries.startTime))
.all(); .all();
@@ -140,9 +130,9 @@ const statsByMember = teamMembers.map(member => {
}; };
}).sort((a, b) => b.totalTime - a.totalTime); }).sort((a, b) => b.totalTime - a.totalTime);
const statsByCategory = allCategories.map(category => { const statsByTag = allTags.map(tag => {
const categoryEntries = entries.filter(e => e.category.id === category.id); const tagEntries = entries.filter(e => e.tag?.id === tag.id);
const totalTime = categoryEntries.reduce((sum, e) => { const totalTime = tagEntries.reduce((sum, e) => {
if (e.entry.endTime) { if (e.entry.endTime) {
return sum + (e.entry.endTime.getTime() - e.entry.startTime.getTime()); return sum + (e.entry.endTime.getTime() - e.entry.startTime.getTime());
} }
@@ -150,9 +140,9 @@ const statsByCategory = allCategories.map(category => {
}, 0); }, 0);
return { return {
category, tag,
totalTime, totalTime,
entryCount: categoryEntries.length, entryCount: tagEntries.length,
}; };
}).sort((a, b) => b.totalTime - a.totalTime); }).sort((a, b) => b.totalTime - a.totalTime);
@@ -247,13 +237,6 @@ const revenueByClient = allClients.map(client => {
}; };
}).filter(s => s.revenue > 0).sort((a, b) => b.revenue - a.revenue); }).filter(s => s.revenue > 0).sort((a, b) => b.revenue - a.revenue);
function formatCurrency(amount: number, currency: string = 'USD') {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: currency,
}).format(amount / 100);
}
function getTimeRangeLabel(range: string) { function getTimeRangeLabel(range: string) {
switch (range) { switch (range) {
case 'today': return 'Today'; case 'today': return 'Today';
@@ -269,17 +252,15 @@ function getTimeRangeLabel(range: string) {
--- ---
<DashboardLayout title="Reports - Chronus"> <DashboardLayout title="Reports - Chronus">
<h1 class="text-3xl font-bold mb-6">Team Reports</h1> <h1 class="text-2xl font-extrabold tracking-tight mb-6">Team Reports</h1>
<!-- Filters --> <!-- Filters -->
<div class="card bg-base-200 shadow-xl border border-base-300 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<form method="GET" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"> <form method="GET" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3">
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Time Range</legend>
<span class="label-text font-medium">Time Range</span> <select id="reports-range" name="range" class="select w-full" onchange="this.form.submit()">
</label>
<select name="range" class="select select-bordered" onchange="this.form.submit()">
<option value="today" selected={timeRange === 'today'}>Today</option> <option value="today" selected={timeRange === 'today'}>Today</option>
<option value="week" selected={timeRange === 'week'}>Last 7 Days</option> <option value="week" selected={timeRange === 'week'}>Last 7 Days</option>
<option value="month" selected={timeRange === 'month'}>Last 30 Days</option> <option value="month" selected={timeRange === 'month'}>Last 30 Days</option>
@@ -288,42 +269,38 @@ function getTimeRangeLabel(range: string) {
<option value="last-month" selected={timeRange === 'last-month'}>Last Month</option> <option value="last-month" selected={timeRange === 'last-month'}>Last Month</option>
<option value="custom" selected={timeRange === 'custom'}>Custom Range</option> <option value="custom" selected={timeRange === 'custom'}>Custom Range</option>
</select> </select>
</div> </fieldset>
{timeRange === 'custom' && ( {timeRange === 'custom' && (
<> <>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">From Date</legend>
<span class="label-text font-medium">From Date</span>
</label>
<input <input
type="date" type="date"
id="reports-from"
name="from" name="from"
class="input input-bordered w-full" class="input w-full"
value={customFrom || (startDate.getFullYear() + '-' + String(startDate.getMonth() + 1).padStart(2, '0') + '-' + String(startDate.getDate()).padStart(2, '0'))} value={customFrom || (startDate.getFullYear() + '-' + String(startDate.getMonth() + 1).padStart(2, '0') + '-' + String(startDate.getDate()).padStart(2, '0'))}
onchange="this.form.submit()" onchange="this.form.submit()"
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">To Date</legend>
<span class="label-text font-medium">To Date</span>
</label>
<input <input
type="date" type="date"
id="reports-to"
name="to" name="to"
class="input input-bordered w-full" class="input w-full"
value={customTo || (endDate.getFullYear() + '-' + String(endDate.getMonth() + 1).padStart(2, '0') + '-' + String(endDate.getDate()).padStart(2, '0'))} value={customTo || (endDate.getFullYear() + '-' + String(endDate.getMonth() + 1).padStart(2, '0') + '-' + String(endDate.getDate()).padStart(2, '0'))}
onchange="this.form.submit()" onchange="this.form.submit()"
/> />
</div> </fieldset>
</> </>
)} )}
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Team Member</legend>
<span class="label-text font-medium">Team Member</span> <select id="reports-member" name="member" class="select w-full" onchange="this.form.submit()">
</label>
<select name="member" class="select select-bordered" onchange="this.form.submit()">
<option value="">All Members</option> <option value="">All Members</option>
{teamMembers.map(member => ( {teamMembers.map(member => (
<option value={member.id} selected={selectedMemberId === member.id}> <option value={member.id} selected={selectedMemberId === member.id}>
@@ -331,27 +308,23 @@ function getTimeRangeLabel(range: string) {
</option> </option>
))} ))}
</select> </select>
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Tag</legend>
<span class="label-text font-medium">Category</span> <select id="reports-tag" name="tag" class="select w-full" onchange="this.form.submit()">
</label> <option value="">All Tags</option>
<select name="category" class="select select-bordered" onchange="this.form.submit()"> {allTags.map(tag => (
<option value="">All Categories</option> <option value={tag.id} selected={selectedTagId === tag.id}>
{allCategories.map(category => ( {tag.name}
<option value={category.id} selected={selectedCategoryId === category.id}>
{category.name}
</option> </option>
))} ))}
</select> </select>
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Client</legend>
<span class="label-text font-medium">Client</span> <select id="reports-client" name="client" class="select w-full" onchange="this.form.submit()">
</label>
<select name="client" class="select select-bordered" onchange="this.form.submit()">
<option value="">All Clients</option> <option value="">All Clients</option>
{allClients.map(client => ( {allClients.map(client => (
<option value={client.id} selected={selectedClientId === client.id}> <option value={client.id} selected={selectedClientId === client.id}>
@@ -359,78 +332,49 @@ function getTimeRangeLabel(range: string) {
</option> </option>
))} ))}
</select> </select>
</div> </fieldset>
</form> </form>
<style>
@media (max-width: 767px) {
form {
align-items: stretch !important;
}
.form-control {
width: 100%;
}
}
select, input {
width: 100%;
}
</style>
</div> </div>
</div> </div>
<!-- Summary Stats --> <!-- Summary Stats -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6"> <div class="grid grid-cols-2 lg:grid-cols-4 gap-3 mb-6">
<div class="stats shadow border border-base-300"> <StatCard
<div class="stat"> title="Total Time"
<div class="stat-figure text-primary"> value={formatDuration(totalTime)}
<Icon name="heroicons:clock" class="w-8 h-8" /> description={getTimeRangeLabel(timeRange)}
</div> icon="heroicons:clock"
<div class="stat-title">Total Time</div> color="text-primary"
<div class="stat-value text-primary">{formatDuration(totalTime)}</div> />
<div class="stat-desc">{getTimeRangeLabel(timeRange)}</div> <StatCard
</div> title="Total Entries"
</div> value={String(entries.length)}
description={getTimeRangeLabel(timeRange)}
<div class="stats shadow border border-base-300"> icon="heroicons:list-bullet"
<div class="stat"> color="text-secondary"
<div class="stat-figure text-secondary"> />
<Icon name="heroicons:list-bullet" class="w-8 h-8" /> <StatCard
</div> title="Revenue"
<div class="stat-title">Total Entries</div> value={formatCurrency(revenueStats.total)}
<div class="stat-value text-secondary">{entries.length}</div> description={`${invoiceStats.paid} paid invoices`}
<div class="stat-desc">{getTimeRangeLabel(timeRange)}</div> icon="heroicons:currency-dollar"
</div> color="text-success"
</div> />
<StatCard
<div class="stats shadow border border-base-300"> title="Active Members"
<div class="stat"> value={String(statsByMember.filter(s => s.entryCount > 0).length)}
<div class="stat-figure text-success"> description={`of ${teamMembers.length} total`}
<Icon name="heroicons:currency-dollar" class="w-8 h-8" /> icon="heroicons:user-group"
</div> color="text-accent"
<div class="stat-title">Revenue</div> />
<div class="stat-value text-success">{formatCurrency(revenueStats.total)}</div>
<div class="stat-desc">{invoiceStats.paid} paid invoices</div>
</div>
</div>
<div class="stats shadow border border-base-300">
<div class="stat">
<div class="stat-figure text-accent">
<Icon name="heroicons:user-group" class="w-8 h-8" />
</div>
<div class="stat-title">Active Members</div>
<div class="stat-value text-accent">{statsByMember.filter(s => s.entryCount > 0).length}</div>
<div class="stat-desc">of {teamMembers.length} total</div>
</div>
</div>
</div> </div>
<!-- Invoice & Quote Stats --> <!-- Invoice & Quote Stats -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:document-text" class="w-6 h-6" /> <Icon name="heroicons:document-text" class="w-4 h-4" />
Invoices Overview Invoices Overview
</h2> </h2>
<div class="grid grid-cols-2 gap-4"> <div class="grid grid-cols-2 gap-4">
@@ -463,10 +407,10 @@ function getTimeRangeLabel(range: string) {
</div> </div>
</div> </div>
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:clipboard-document-list" class="w-6 h-6" /> <Icon name="heroicons:clipboard-document-list" class="w-4 h-4" />
Quotes Overview Quotes Overview
</h2> </h2>
<div class="grid grid-cols-2 gap-4"> <div class="grid grid-cols-2 gap-4">
@@ -504,14 +448,14 @@ function getTimeRangeLabel(range: string) {
<!-- Revenue by Client - Only show if there's revenue data and no client filter --> <!-- Revenue by Client - Only show if there's revenue data and no client filter -->
{!selectedClientId && revenueByClient.length > 0 && ( {!selectedClientId && revenueByClient.length > 0 && (
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:banknotes" class="w-6 h-6" /> <Icon name="heroicons:banknotes" class="w-4 h-4" />
Revenue by Client Revenue by Client
</h2> </h2>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Client</th> <th>Client</th>
@@ -524,11 +468,11 @@ function getTimeRangeLabel(range: string) {
{revenueByClient.slice(0, 10).map(stat => ( {revenueByClient.slice(0, 10).map(stat => (
<tr> <tr>
<td> <td>
<div class="font-bold">{stat.client.name}</div> <div class="font-medium">{stat.client.name}</div>
</td> </td>
<td class="font-mono font-bold text-success">{formatCurrency(stat.revenue)}</td> <td class="font-mono font-semibold text-success text-sm">{formatCurrency(stat.revenue)}</td>
<td>{stat.invoiceCount}</td> <td>{stat.invoiceCount}</td>
<td class="font-mono"> <td class="font-mono text-sm">
{stat.invoiceCount > 0 ? formatCurrency(stat.revenue / stat.invoiceCount) : formatCurrency(0)} {stat.invoiceCount > 0 ? formatCurrency(stat.revenue / stat.invoiceCount) : formatCurrency(0)}
</td> </td>
</tr> </tr>
@@ -543,22 +487,22 @@ function getTimeRangeLabel(range: string) {
{/* Charts Section - Only show if there's data */} {/* Charts Section - Only show if there's data */}
{totalTime > 0 && ( {totalTime > 0 && (
<> <>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6"> <div class="grid grid-cols-1 lg:grid-cols-2 gap-4 mb-6">
{/* Category Distribution Chart - Only show when no category filter */} {/* Tag Distribution Chart - Only show when no tag filter */}
{!selectedCategoryId && statsByCategory.filter(s => s.totalTime > 0).length > 0 && ( {!selectedTagId && statsByTag.filter(s => s.totalTime > 0).length > 0 && (
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:chart-pie" class="w-6 h-6" /> <Icon name="heroicons:chart-pie" class="w-4 h-4" />
Category Distribution Tag Distribution
</h2> </h2>
<div class="h-64 w-full"> <div class="h-64 w-full">
<CategoryChart <TagChart
client:visible client:visible
categories={statsByCategory.filter(s => s.totalTime > 0).map(s => ({ tags={statsByTag.filter(s => s.totalTime > 0).map(s => ({
name: s.category.name, name: s.tag.name,
totalTime: s.totalTime, totalTime: s.totalTime,
color: s.category.color || '#3b82f6' color: s.tag.color || '#3b82f6'
}))} }))}
/> />
</div> </div>
@@ -568,10 +512,10 @@ function getTimeRangeLabel(range: string) {
{/* Client Distribution Chart - Only show when no client filter */} {/* Client Distribution Chart - Only show when no client filter */}
{!selectedClientId && statsByClient.filter(s => s.totalTime > 0).length > 0 && ( {!selectedClientId && statsByClient.filter(s => s.totalTime > 0).length > 0 && (
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:chart-bar" class="w-6 h-6" /> <Icon name="heroicons:chart-bar" class="w-4 h-4" />
Time by Client Time by Client
</h2> </h2>
<div class="h-64 w-full"> <div class="h-64 w-full">
@@ -590,10 +534,10 @@ function getTimeRangeLabel(range: string) {
{/* Team Member Chart - Only show when no member filter */} {/* Team Member Chart - Only show when no member filter */}
{!selectedMemberId && statsByMember.filter(s => s.totalTime > 0).length > 0 && ( {!selectedMemberId && statsByMember.filter(s => s.totalTime > 0).length > 0 && (
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:users" class="w-6 h-6" /> <Icon name="heroicons:users" class="w-4 h-4" />
Time by Team Member Time by Team Member
</h2> </h2>
<div class="h-64 w-full"> <div class="h-64 w-full">
@@ -613,14 +557,14 @@ function getTimeRangeLabel(range: string) {
{/* Stats by Member - Only show if there's data and no member filter */} {/* Stats by Member - Only show if there's data and no member filter */}
{!selectedMemberId && statsByMember.filter(s => s.totalTime > 0).length > 0 && ( {!selectedMemberId && statsByMember.filter(s => s.totalTime > 0).length > 0 && (
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:users" class="w-6 h-6" /> <Icon name="heroicons:users" class="w-4 h-4" />
By Team Member By Team Member
</h2> </h2>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Member</th> <th>Member</th>
@@ -634,13 +578,13 @@ function getTimeRangeLabel(range: string) {
<tr> <tr>
<td> <td>
<div> <div>
<div class="font-bold">{stat.member.name}</div> <div class="font-medium">{stat.member.name}</div>
<div class="text-sm opacity-50">{stat.member.email}</div> <div class="text-xs text-base-content/40">{stat.member.email}</div>
</div> </div>
</td> </td>
<td class="font-mono">{formatDuration(stat.totalTime)}</td> <td class="font-mono text-sm">{formatDuration(stat.totalTime)}</td>
<td>{stat.entryCount}</td> <td>{stat.entryCount}</td>
<td class="font-mono"> <td class="font-mono text-sm">
{stat.entryCount > 0 ? formatDuration(stat.totalTime / stat.entryCount) : '00:00:00 (0m)'} {stat.entryCount > 0 ? formatDuration(stat.totalTime / stat.entryCount) : '00:00:00 (0m)'}
</td> </td>
</tr> </tr>
@@ -652,45 +596,45 @@ function getTimeRangeLabel(range: string) {
</div> </div>
)} )}
{/* Stats by Category - Only show if there's data and no category filter */} {/* Stats by Tag - Only show if there's data and no tag filter */}
{!selectedCategoryId && statsByCategory.filter(s => s.totalTime > 0).length > 0 && ( {!selectedTagId && statsByTag.filter(s => s.totalTime > 0).length > 0 && (
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:tag" class="w-6 h-6" /> <Icon name="heroicons:tag" class="w-4 h-4" />
By Category By Tag
</h2> </h2>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Category</th> <th>Tag</th>
<th>Total Time</th> <th>Total Time</th>
<th>Entries</th> <th>Entries</th>
<th>% of Total</th> <th>% of Total</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{statsByCategory.filter(s => s.totalTime > 0).map(stat => ( {statsByTag.filter(s => s.totalTime > 0).map(stat => (
<tr> <tr>
<td> <td>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
{stat.category.color && ( {stat.tag.color && (
<span class="w-4 h-4 rounded-full" style={`background-color: ${stat.category.color}`}></span> <span class="w-3 h-3 rounded-full" style={`background-color: ${stat.tag.color}`}></span>
)} )}
<span>{stat.category.name}</span> <span>{stat.tag.name}</span>
</div> </div>
</td> </td>
<td class="font-mono">{formatDuration(stat.totalTime)}</td> <td class="font-mono text-sm">{formatDuration(stat.totalTime)}</td>
<td>{stat.entryCount}</td> <td>{stat.entryCount}</td>
<td> <td>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<progress <progress
class="progress progress-primary w-20" class="progress progress-primary w-16"
value={stat.totalTime} value={stat.totalTime}
max={totalTime} max={totalTime}
></progress> ></progress>
<span class="text-sm"> <span class="text-xs">
{totalTime > 0 ? Math.round((stat.totalTime / totalTime) * 100) : 0}% {totalTime > 0 ? Math.round((stat.totalTime / totalTime) * 100) : 0}%
</span> </span>
</div> </div>
@@ -706,14 +650,14 @@ function getTimeRangeLabel(range: string) {
{/* Stats by Client - Only show if there's data and no client filter */} {/* Stats by Client - Only show if there's data and no client filter */}
{!selectedClientId && statsByClient.filter(s => s.totalTime > 0).length > 0 && ( {!selectedClientId && statsByClient.filter(s => s.totalTime > 0).length > 0 && (
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-3">
<Icon name="heroicons:building-office" class="w-6 h-6" /> <Icon name="heroicons:building-office" class="w-4 h-4" />
By Client By Client
</h2> </h2>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Client</th> <th>Client</th>
@@ -726,16 +670,16 @@ function getTimeRangeLabel(range: string) {
{statsByClient.filter(s => s.totalTime > 0).map(stat => ( {statsByClient.filter(s => s.totalTime > 0).map(stat => (
<tr> <tr>
<td>{stat.client.name}</td> <td>{stat.client.name}</td>
<td class="font-mono">{formatDuration(stat.totalTime)}</td> <td class="font-mono text-sm">{formatDuration(stat.totalTime)}</td>
<td>{stat.entryCount}</td> <td>{stat.entryCount}</td>
<td> <td>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<progress <progress
class="progress progress-secondary w-20" class="progress progress-secondary w-16"
value={stat.totalTime} value={stat.totalTime}
max={totalTime} max={totalTime}
></progress> ></progress>
<span class="text-sm"> <span class="text-xs">
{totalTime > 0 ? Math.round((stat.totalTime / totalTime) * 100) : 0}% {totalTime > 0 ? Math.round((stat.totalTime / totalTime) * 100) : 0}%
</span> </span>
</div> </div>
@@ -750,29 +694,29 @@ function getTimeRangeLabel(range: string) {
)} )}
{/* Detailed Entries */} {/* Detailed Entries */}
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<div class="flex justify-between items-center mb-4"> <div class="flex justify-between items-center mb-3">
<h2 class="card-title"> <h2 class="text-sm font-semibold flex items-center gap-2">
<Icon name="heroicons:document-text" class="w-6 h-6" /> <Icon name="heroicons:document-text" class="w-4 h-4" />
Detailed Entries ({entries.length}) Detailed Entries ({entries.length})
</h2> </h2>
{entries.length > 0 && ( {entries.length > 0 && (
<a href={`/api/reports/export${url.search}`} class="btn btn-sm btn-outline" target="_blank"> <a href={`/api/reports/export${url.search}`} class="btn btn-xs btn-ghost" target="_blank">
<Icon name="heroicons:arrow-down-tray" class="w-4 h-4" /> <Icon name="heroicons:arrow-down-tray" class="w-3.5 h-3.5" />
Export CSV Export CSV
</a> </a>
)} )}
</div> </div>
{entries.length > 0 ? ( {entries.length > 0 ? (
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table table-zebra"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Date</th> <th>Date</th>
<th>Member</th> <th>Member</th>
<th>Client</th> <th>Client</th>
<th>Category</th> <th>Tag</th>
<th>Description</th> <th>Description</th>
<th>Duration</th> <th>Duration</th>
</tr> </tr>
@@ -782,22 +726,26 @@ function getTimeRangeLabel(range: string) {
<tr> <tr>
<td class="whitespace-nowrap"> <td class="whitespace-nowrap">
{e.entry.startTime.toLocaleDateString()}<br/> {e.entry.startTime.toLocaleDateString()}<br/>
<span class="text-xs opacity-50"> <span class="text-xs text-base-content/40">
{e.entry.startTime.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})} {e.entry.startTime.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}
</span> </span>
</td> </td>
<td>{e.user.name}</td> <td>{e.user.name}</td>
<td>{e.client.name}</td> <td>{e.client.name}</td>
<td> <td>
<div class="flex items-center gap-2"> {e.tag ? (
{e.category.color && ( <div class="badge badge-xs badge-outline flex items-center gap-1">
<span class="w-3 h-3 rounded-full" style={`background-color: ${e.category.color}`}></span> {e.tag.color && (
)} <span class="w-2 h-2 rounded-full" style={`background-color: ${e.tag.color}`}></span>
<span>{e.category.name}</span> )}
</div> <span>{e.tag.name}</span>
</div>
) : (
<span class="text-base-content/30">-</span>
)}
</td> </td>
<td>{e.entry.description || '-'}</td> <td class="text-base-content/60">{e.entry.description || '-'}</td>
<td class="font-mono"> <td class="font-mono text-sm">
{e.entry.endTime {e.entry.endTime
? formatDuration(e.entry.endTime.getTime() - e.entry.startTime.getTime()) ? formatDuration(e.entry.endTime.getTime() - e.entry.startTime.getTime())
: 'Running...' : 'Running...'
@@ -809,12 +757,12 @@ function getTimeRangeLabel(range: string) {
</table> </table>
</div> </div>
) : ( ) : (
<div class="flex flex-col items-center justify-center py-12 text-center"> <div class="flex flex-col items-center justify-center py-10 text-center">
<Icon name="heroicons:inbox" class="w-16 h-16 text-base-content/20 mb-4" /> <Icon name="heroicons:inbox" class="w-12 h-12 text-base-content/15 mb-3" />
<h3 class="text-lg font-semibold mb-2">No time entries found</h3> <h3 class="text-base font-semibold mb-1">No time entries found</h3>
<p class="text-base-content/60 mb-4">Try adjusting your filters or select a different time range.</p> <p class="text-base-content/50 text-sm mb-4">Try adjusting your filters or select a different time range.</p>
<a href="/dashboard/tracker" class="btn btn-primary"> <a href="/dashboard/tracker" class="btn btn-primary btn-sm">
<Icon name="heroicons:play" class="w-5 h-5" /> <Icon name="heroicons:play" class="w-4 h-4" />
Start Tracking Time Start Tracking Time
</a> </a>
</div> </div>

View File

@@ -30,7 +30,7 @@ const userPasskeys = await db.select()
<DashboardLayout title="Account Settings - Chronus"> <DashboardLayout title="Account Settings - Chronus">
<div class="max-w-4xl mx-auto px-4 sm:px-6"> <div class="max-w-4xl mx-auto px-4 sm:px-6">
<h1 class="text-2xl sm:text-3xl font-bold mb-6 sm:mb-8 text-primary"> <h1 class="text-2xl font-extrabold tracking-tight mb-6 sm:mb-8">
Account Settings Account Settings
</h1> </h1>
@@ -50,10 +50,10 @@ const userPasskeys = await db.select()
)} )}
<!-- Profile Information --> <!-- Profile Information -->
<ProfileForm client:load user={user} /> <ProfileForm client:idle user={user} />
<!-- Change Password --> <!-- Change Password -->
<PasswordForm client:load /> <PasswordForm client:idle />
<!-- Passkeys --> <!-- Passkeys -->
<PasskeyManager client:idle initialPasskeys={userPasskeys.map(pk => ({ <PasskeyManager client:idle initialPasskeys={userPasskeys.map(pk => ({
@@ -69,25 +69,25 @@ const userPasskeys = await db.select()
createdAt: t.createdAt ? t.createdAt.toISOString() : '' createdAt: t.createdAt ? t.createdAt.toISOString() : ''
}))} /> }))} />
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body p-4 sm:p-6"> <div class="card-body p-4">
<h2 class="card-title mb-6 text-lg sm:text-xl"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-4">
<Icon name="heroicons:information-circle" class="w-5 h-5 sm:w-6 sm:h-6" /> <Icon name="heroicons:information-circle" class="w-4 h-4" />
Account Information Account Information
</h2> </h2>
<div class="space-y-3"> <div class="space-y-3">
<div class="flex flex-col sm:flex-row sm:justify-between py-3 border-b border-base-300 gap-2 sm:gap-0"> <div class="flex flex-col sm:flex-row sm:justify-between py-3 border-b border-base-200 gap-2 sm:gap-0">
<span class="text-base-content/70 text-sm sm:text-base">Account ID</span> <span class="text-base-content/60 text-sm">Account ID</span>
<span class="font-mono text-xs sm:text-sm break-all">{user.id}</span> <span class="font-mono text-xs break-all">{user.id}</span>
</div> </div>
<div class="flex flex-col sm:flex-row sm:justify-between py-3 border-b border-base-300 gap-2 sm:gap-0"> <div class="flex flex-col sm:flex-row sm:justify-between py-3 border-b border-base-200 gap-2 sm:gap-0">
<span class="text-base-content/70 text-sm sm:text-base">Email</span> <span class="text-base-content/60 text-sm">Email</span>
<span class="text-sm sm:text-base break-all">{user.email}</span> <span class="text-sm break-all">{user.email}</span>
</div> </div>
<div class="flex flex-col sm:flex-row sm:justify-between py-3 gap-2 sm:gap-0"> <div class="flex flex-col sm:flex-row sm:justify-between py-3 gap-2 sm:gap-0">
<span class="text-base-content/70 text-sm sm:text-base">Site Administrator</span> <span class="text-base-content/60 text-sm">Site Administrator</span>
<span class={user.isSiteAdmin ? "badge badge-primary" : "badge badge-ghost"}> <span class={user.isSiteAdmin ? "badge badge-xs badge-primary" : "badge badge-xs badge-ghost"}>
{user.isSiteAdmin ? "Yes" : "No"} {user.isSiteAdmin ? "Yes" : "No"}
</span> </span>
</div> </div>

View File

@@ -5,24 +5,13 @@ import { Icon } from 'astro-icon/components';
import { db } from '../../db'; import { db } from '../../db';
import { members, users } from '../../db/schema'; import { members, users } from '../../db/schema';
import { eq } from 'drizzle-orm'; import { eq } from 'drizzle-orm';
import { getCurrentTeam } from '../../lib/getCurrentTeam';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const teamMembers = await db.select({ const teamMembers = await db.select({
member: members, member: members,
@@ -39,24 +28,27 @@ const isAdmin = currentUserMember?.member.role === 'owner' || currentUserMember?
<DashboardLayout title="Team - Chronus"> <DashboardLayout title="Team - Chronus">
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6"> <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6">
<h1 class="text-3xl font-bold">Team Members</h1> <div>
<h1 class="text-2xl font-extrabold tracking-tight">Team Members</h1>
<p class="text-base-content/60 text-sm mt-1">Manage your organization's team</p>
</div>
<div class="flex gap-2"> <div class="flex gap-2">
{isAdmin && ( {isAdmin && (
<> <>
<a href="/dashboard/team/settings" class="btn btn-ghost"> <a href="/dashboard/team/settings" class="btn btn-ghost btn-sm">
<Icon name="heroicons:cog-6-tooth" class="w-5 h-5" /> <Icon name="heroicons:cog-6-tooth" class="w-4 h-4" />
Settings Settings
</a> </a>
<a href="/dashboard/team/invite" class="btn btn-primary">Invite Member</a> <a href="/dashboard/team/invite" class="btn btn-primary btn-sm">Invite Member</a>
</> </>
)} )}
</div> </div>
</div> </div>
<div class="card bg-base-100 shadow-xl border border-base-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-0">
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@@ -68,21 +60,21 @@ const isAdmin = currentUserMember?.member.role === 'owner' || currentUserMember?
</thead> </thead>
<tbody> <tbody>
{teamMembers.map(({ member, user: teamUser }) => ( {teamMembers.map(({ member, user: teamUser }) => (
<tr> <tr class="hover">
<td> <td>
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<Avatar name={teamUser.name} /> <Avatar name={teamUser.name} />
<div> <div>
<div class="font-bold">{teamUser.name}</div> <div class="font-medium">{teamUser.name}</div>
{teamUser.id === user.id && ( {teamUser.id === user.id && (
<span class="badge badge-sm">You</span> <span class="badge badge-xs">You</span>
)} )}
</div> </div>
</div> </div>
</td> </td>
<td>{teamUser.email}</td> <td class="text-base-content/60">{teamUser.email}</td>
<td> <td>
<span class={`badge ${ <span class={`badge badge-xs ${
member.role === 'owner' ? 'badge-primary' : member.role === 'owner' ? 'badge-primary' :
member.role === 'admin' ? 'badge-secondary' : member.role === 'admin' ? 'badge-secondary' :
'badge-ghost' 'badge-ghost'
@@ -90,15 +82,15 @@ const isAdmin = currentUserMember?.member.role === 'owner' || currentUserMember?
{member.role} {member.role}
</span> </span>
</td> </td>
<td>{member.joinedAt?.toLocaleDateString() ?? 'N/A'}</td> <td class="text-base-content/40">{member.joinedAt?.toLocaleDateString() ?? 'N/A'}</td>
{isAdmin && ( {isAdmin && (
<td> <td>
{teamUser.id !== user.id && member.role !== 'owner' && ( {teamUser.id !== user.id && member.role !== 'owner' && (
<div class="dropdown dropdown-end"> <div class="dropdown dropdown-end">
<label tabindex="0" class="btn btn-ghost btn-sm"> <div role="button" tabindex="0" class="btn btn-ghost btn-xs btn-square">
<Icon name="heroicons:ellipsis-vertical" class="w-5 h-5" /> <Icon name="heroicons:ellipsis-vertical" class="w-4 h-4" />
</label> </div>
<ul tabindex="0" class="dropdown-content z-1 menu p-2 shadow bg-base-100 rounded-box w-52 border border-base-200"> <ul tabindex="0" class="dropdown-content z-1 menu p-2 bg-base-100 rounded-box w-52 border border-base-200">
<li> <li>
<form method="POST" action={`/api/team/change-role`}> <form method="POST" action={`/api/team/change-role`}>
<input type="hidden" name="userId" value={teamUser.id} /> <input type="hidden" name="userId" value={teamUser.id} />

View File

@@ -29,45 +29,39 @@ if (!isAdmin) return Astro.redirect('/dashboard/team');
<DashboardLayout title="Invite Team Member - Chronus"> <DashboardLayout title="Invite Team Member - Chronus">
<div class="max-w-2xl mx-auto"> <div class="max-w-2xl mx-auto">
<h1 class="text-3xl font-bold mb-6">Invite Team Member</h1> <h1 class="text-2xl font-extrabold tracking-tight mb-6">Invite Team Member</h1>
<form method="POST" action="/api/team/invite" class="card bg-base-100 shadow-xl border border-base-200"> <form method="POST" action="/api/team/invite" class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<div class="alert alert-info mb-4"> <div class="alert alert-info mb-4">
<Icon name="heroicons:information-circle" class="w-6 h-6" /> <Icon name="heroicons:information-circle" class="w-4 h-4 shrink-0" />
<span>The user must already have an account. They'll be added to your organization.</span> <span class="text-sm">The user must already have an account. They'll be added to your organization.</span>
</div> </div>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="email"> <legend class="fieldset-legend text-xs">Email Address</legend>
<span class="label-text">Email Address</span>
</label>
<input <input
type="email" type="email"
id="email" id="email"
name="email" name="email"
placeholder="user@example.com" placeholder="user@example.com"
class="input input-bordered" class="input"
required required
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label" for="role"> <legend class="fieldset-legend text-xs">Role</legend>
<span class="label-text">Role</span> <select id="role" name="role" class="select" required>
</label>
<select id="role" name="role" class="select select-bordered" required>
<option value="member">Member</option> <option value="member">Member</option>
<option value="admin">Admin</option> <option value="admin">Admin</option>
</select> </select>
<label class="label"> <p class="text-xs text-base-content/40 mt-1">Members can track time. Admins can manage team and clients.</p>
<span class="label-text-alt">Members can track time. Admins can manage team and clients.</span> </fieldset>
</label>
</div>
<div class="card-actions justify-end mt-6"> <div class="flex justify-end gap-2 mt-4">
<a href="/dashboard/team" class="btn btn-ghost">Cancel</a> <a href="/dashboard/team" class="btn btn-ghost btn-sm">Cancel</a>
<button type="submit" class="btn btn-primary">Invite Member</button> <button type="submit" class="btn btn-primary btn-sm">Invite Member</button>
</div> </div>
</div> </div>
</form> </form>

View File

@@ -2,26 +2,15 @@
import DashboardLayout from '../../../layouts/DashboardLayout.astro'; import DashboardLayout from '../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components'; import { Icon } from 'astro-icon/components';
import { db } from '../../../db'; import { db } from '../../../db';
import { categories, members, organizations } from '../../../db/schema'; import { organizations, tags } from '../../../db/schema';
import { eq } from 'drizzle-orm'; import { eq } from 'drizzle-orm';
import { getCurrentTeam } from '../../../lib/getCurrentTeam';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const isAdmin = userMembership.role === 'owner' || userMembership.role === 'admin'; const isAdmin = userMembership.role === 'owner' || userMembership.role === 'admin';
if (!isAdmin) return Astro.redirect('/dashboard/team'); if (!isAdmin) return Astro.redirect('/dashboard/team');
@@ -35,9 +24,11 @@ const organization = await db.select()
if (!organization) return Astro.redirect('/dashboard'); if (!organization) return Astro.redirect('/dashboard');
const allCategories = await db.select()
.from(categories)
.where(eq(categories.organizationId, orgId)) const allTags = await db.select()
.from(tags)
.where(eq(tags.organizationId, orgId))
.all(); .all();
const url = new URL(Astro.request.url); const url = new URL(Astro.request.url);
@@ -46,42 +37,40 @@ const successType = url.searchParams.get('success');
<DashboardLayout title="Team Settings - Chronus"> <DashboardLayout title="Team Settings - Chronus">
<div class="flex items-center gap-3 mb-6"> <div class="flex items-center gap-3 mb-6">
<a href="/dashboard/team" class="btn btn-ghost btn-sm"> <a href="/dashboard/team" class="btn btn-ghost btn-xs">
<Icon name="heroicons:arrow-left" class="w-5 h-5" /> <Icon name="heroicons:arrow-left" class="w-4 h-4" />
</a> </a>
<h1 class="text-3xl font-bold">Team Settings</h1> <h1 class="text-2xl font-extrabold tracking-tight">Team Settings</h1>
</div> </div>
<!-- Team Settings --> <!-- Team Settings -->
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<h2 class="card-title mb-4"> <h2 class="text-sm font-semibold flex items-center gap-2 mb-4">
<Icon name="heroicons:building-office-2" class="w-6 h-6" /> <Icon name="heroicons:building-office-2" class="w-4 h-4" />
Team Settings Team Settings
</h2> </h2>
{successType === 'org-name' && ( {successType === 'org-name' && (
<div class="alert alert-success mb-4"> <div class="alert alert-success mb-4">
<Icon name="heroicons:check-circle" class="w-6 h-6" /> <Icon name="heroicons:check-circle" class="w-4 h-4" />
<span>Team information updated successfully!</span> <span class="text-sm">Team information updated successfully!</span>
</div> </div>
)} )}
<form <form
action="/api/organizations/update-name" action="/api/organizations/update-name"
method="POST" method="POST"
class="space-y-4" class="space-y-3"
enctype="multipart/form-data" enctype="multipart/form-data"
> >
<input type="hidden" name="organizationId" value={organization.id} /> <input type="hidden" name="organizationId" value={organization.id} />
<div class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Team Logo</legend>
<span class="label-text font-medium">Team Logo</span> <div class="flex items-center gap-4">
</div>
<div class="flex items-center gap-6">
<div class="avatar placeholder"> <div class="avatar placeholder">
<div class="bg-base-200 text-neutral-content rounded-xl w-24 border border-base-300 flex items-center justify-center overflow-hidden"> <div class="bg-base-200 text-neutral-content rounded-xl w-20 border border-base-200 flex items-center justify-center overflow-hidden">
{organization.logoUrl ? ( {organization.logoUrl ? (
<img <img
src={organization.logoUrl} src={organization.logoUrl}
@@ -91,7 +80,7 @@ const successType = url.searchParams.get('success');
) : ( ) : (
<Icon <Icon
name="heroicons:photo" name="heroicons:photo"
class="w-8 h-8 opacity-40 text-base-content" class="w-6 h-6 opacity-40 text-base-content"
/> />
)} )}
</div> </div>
@@ -101,112 +90,135 @@ const successType = url.searchParams.get('success');
type="file" type="file"
name="logo" name="logo"
accept="image/png, image/jpeg" accept="image/png, image/jpeg"
class="file-input file-input-bordered w-full max-w-xs" class="file-input file-input-bordered file-input-sm w-full max-w-xs"
/> />
<div class="text-xs text-base-content/60 mt-2"> <div class="text-xs text-base-content/40 mt-1">
Upload a company logo (PNG, JPG). Upload a company logo (PNG, JPG). Will be displayed on invoices and quotes.
<br />
Will be displayed on invoices and quotes.
</div> </div>
</div> </div>
</div> </div>
</div> </fieldset>
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Team Name</legend>
<span class="label-text font-medium">Team Name</span>
</div>
<input <input
type="text" type="text"
id="team-name"
name="name" name="name"
value={organization.name} value={organization.name}
placeholder="Organization name" placeholder="Organization name"
class="input input-bordered w-full" class="input w-full"
required required
/> />
<div class="label"> <p class="text-xs text-base-content/40 mt-1">This name is visible to all team members</p>
<span class="label-text-alt text-base-content/60">This name is visible to all team members</span> </fieldset>
</div>
</label>
<div class="divider">Address Information</div> <div class="divider text-xs text-base-content/40 my-2">Address Information</div>
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Street Address</legend>
<span class="label-text font-medium">Street Address</span>
</div>
<input <input
type="text" type="text"
id="team-street"
name="street" name="street"
value={organization.street || ''} value={organization.street || ''}
placeholder="123 Main Street" placeholder="123 Main Street"
class="input input-bordered w-full" class="input w-full"
/> />
</label> </fieldset>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">City</legend>
<span class="label-text font-medium">City</span>
</div>
<input <input
type="text" type="text"
id="team-city"
name="city" name="city"
value={organization.city || ''} value={organization.city || ''}
placeholder="City" placeholder="City"
class="input input-bordered w-full" class="input w-full"
/> />
</label> </fieldset>
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">State/Province</legend>
<span class="label-text font-medium">State/Province</span>
</div>
<input <input
type="text" type="text"
id="team-state"
name="state" name="state"
value={organization.state || ''} value={organization.state || ''}
placeholder="State/Province" placeholder="State/Province"
class="input input-bordered w-full" class="input w-full"
/> />
</label> </fieldset>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Postal Code</legend>
<span class="label-text font-medium">Postal Code</span>
</div>
<input <input
type="text" type="text"
id="team-zip"
name="zip" name="zip"
value={organization.zip || ''} value={organization.zip || ''}
placeholder="12345" placeholder="12345"
class="input input-bordered w-full" class="input w-full"
/> />
</label> </fieldset>
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Country</legend>
<span class="label-text font-medium">Country</span>
</div>
<input <input
type="text" type="text"
id="team-country"
name="country" name="country"
value={organization.country || ''} value={organization.country || ''}
placeholder="Country" placeholder="Country"
class="input input-bordered w-full" class="input w-full"
/> />
</label> </fieldset>
</div> </div>
<div class="flex flex-col sm:flex-row justify-between items-center gap-4 mt-6"> <div class="divider text-xs text-base-content/40 my-2">Defaults</div>
<span class="text-xs text-base-content/60 text-center sm:text-left">
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<fieldset class="fieldset">
<legend class="fieldset-legend text-xs">Default Tax Rate (%)</legend>
<input
type="number"
id="default-tax-rate"
name="defaultTaxRate"
step="0.01"
min="0"
max="100"
value={organization.defaultTaxRate || 0}
class="input w-full"
/>
</fieldset>
<fieldset class="fieldset">
<legend class="fieldset-legend text-xs">Default Currency</legend>
<select
id="default-currency"
name="defaultCurrency"
class="select w-full"
>
<option value="USD" selected={!organization.defaultCurrency || organization.defaultCurrency === 'USD'}>USD ($)</option>
<option value="EUR" selected={organization.defaultCurrency === 'EUR'}>EUR (€)</option>
<option value="GBP" selected={organization.defaultCurrency === 'GBP'}>GBP (£)</option>
<option value="CAD" selected={organization.defaultCurrency === 'CAD'}>CAD ($)</option>
<option value="AUD" selected={organization.defaultCurrency === 'AUD'}>AUD ($)</option>
</select>
</fieldset>
</div>
<div class="flex flex-col sm:flex-row justify-between items-center gap-3 mt-4">
<span class="text-xs text-base-content/40 text-center sm:text-left">
Address information appears on invoices and quotes Address information appears on invoices and quotes
</span> </span>
<button type="submit" class="btn btn-primary w-full sm:w-auto"> <button type="submit" class="btn btn-primary btn-sm w-full sm:w-auto">
<Icon name="heroicons:check" class="w-5 h-5" /> <Icon name="heroicons:check" class="w-4 h-4" />
Save Changes Save Changes
</button> </button>
</div> </div>
@@ -214,60 +226,142 @@ const successType = url.searchParams.get('success');
</div> </div>
</div> </div>
<!-- Categories Section --> <!-- Tags Section -->
<div class="card bg-base-100 shadow-xl border border-base-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<div class="flex justify-between items-center mb-4"> <div class="flex justify-between items-center mb-4">
<h2 class="card-title"> <h2 class="text-sm font-semibold flex items-center gap-2">
<Icon name="heroicons:tag" class="w-6 h-6" /> <Icon name="heroicons:tag" class="w-4 h-4" />
Work Categories Tags & Rates
</h2> </h2>
<a href="/dashboard/team/settings/categories/new" class="btn btn-primary btn-sm"> <button onclick="document.getElementById('new_tag_modal').showModal()" class="btn btn-primary btn-xs">
<Icon name="heroicons:plus" class="w-5 h-5" /> <Icon name="heroicons:plus" class="w-3 h-3" />
Add Category Add Tag
</a> </button>
</div> </div>
<p class="text-base-content/70 mb-4"> <p class="text-base-content/60 text-xs mb-4">
Categories help organize time tracking by type of work. All team members use the same categories. Tags can be used to categorize time entries. You can also associate an hourly rate with a tag for billing purposes.
</p> </p>
{allCategories.length === 0 ? ( {allTags.length === 0 ? (
<div class="alert alert-info"> <div class="alert alert-info">
<Icon name="heroicons:information-circle" class="w-6 h-6" /> <Icon name="heroicons:information-circle" class="w-4 h-4" />
<div> <div>
<div class="font-bold">No categories yet</div> <div class="font-semibold text-sm">No tags yet</div>
<div class="text-sm">Create your first category to start organizing time entries.</div> <div class="text-xs">Create tags to add context and rates to your time entries.</div>
</div> </div>
</div> </div>
) : ( ) : (
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> <div class="overflow-x-auto">
{allCategories.map(category => ( <table class="table table-sm">
<div class="card bg-base-200 border border-base-300"> <thead>
<div class="card-body p-4"> <tr>
<div class="flex items-center gap-3"> <th>Name</th>
{category.color && ( <th>Rate / Hr</th>
<span class="w-4 h-4 rounded-full shrink-0" style={`background-color: ${category.color}`}></span> <th class="w-20"></th>
)} </tr>
<div class="grow min-w-0"> </thead>
<h3 class="font-semibold truncate">{category.name}</h3> <tbody>
<p class="text-xs text-base-content/60"> {allTags.map(tag => (
Created {category.createdAt?.toLocaleDateString() ?? 'N/A'} <tr class="hover">
</p> <td>
</div> <div class="flex items-center gap-2">
<a {tag.color && (
href={`/dashboard/team/settings/categories/${category.id}/edit`} <div class="w-3 h-3 rounded-full" style={`background-color: ${tag.color}`}></div>
class="btn btn-ghost btn-xs" )}
> <span class="font-medium">{tag.name}</span>
<Icon name="heroicons:pencil" class="w-4 h-4" /> </div>
</a> </td>
</div> <td>
</div> {tag.rate ? (
</div> <span class="font-mono text-sm">{new Intl.NumberFormat('en-US', { style: 'currency', currency: organization.defaultCurrency || 'USD' }).format(tag.rate / 100)}</span>
))} ) : (
<span class="text-base-content/40 text-xs italic">No rate</span>
)}
</td>
<td>
<div class="flex gap-1">
<button
onclick={`document.getElementById('edit_tag_modal_${tag.id}').showModal()`}
class="btn btn-ghost btn-xs btn-square"
>
<Icon name="heroicons:pencil" class="w-3 h-3" />
</button>
<form method="POST" action={`/api/tags/${tag.id}/delete`} onsubmit="return confirm('Are you sure you want to delete this tag?');">
<button class="btn btn-ghost btn-xs btn-square text-error">
<Icon name="heroicons:trash" class="w-3 h-3" />
</button>
</form>
</div>
{/* Edit Modal */}
<dialog id={`edit_tag_modal_${tag.id}`} class="modal">
<div class="modal-box">
<h3 class="font-semibold text-base">Edit Tag</h3>
<form method="POST" action={`/api/tags/${tag.id}/update`}>
<fieldset class="fieldset mb-3">
<legend class="fieldset-legend text-xs">Name</legend>
<input type="text" name="name" value={tag.name} class="input w-full" required />
</fieldset>
<fieldset class="fieldset mb-3">
<legend class="fieldset-legend text-xs">Color</legend>
<input type="color" name="color" value={tag.color || '#3b82f6'} class="input w-full h-12 p-1" />
</fieldset>
<fieldset class="fieldset mb-4">
<legend class="fieldset-legend text-xs">Hourly Rate (cents)</legend>
<input type="number" name="rate" value={tag.rate || 0} min="0" class="input w-full" />
<p class="text-xs text-base-content/40 mt-1">Enter rate in cents (e.g. 5000 = $50.00)</p>
</fieldset>
<div class="modal-action">
<button type="button" class="btn btn-sm" onclick={`document.getElementById('edit_tag_modal_${tag.id}').close()`}>Cancel</button>
<button type="submit" class="btn btn-primary btn-sm">Save</button>
</div>
</form>
</div>
<form method="dialog" class="modal-backdrop">
<button>close</button>
</form>
</dialog>
</td>
</tr>
))}
</tbody>
</table>
</div> </div>
)} )}
</div> </div>
</div> </div>
<dialog id="new_tag_modal" class="modal">
<div class="modal-box">
<h3 class="font-semibold text-base">New Tag</h3>
<form method="POST" action="/api/tags/create">
<input type="hidden" name="organizationId" value={organization.id} />
<fieldset class="fieldset mb-3">
<legend class="fieldset-legend text-xs">Name</legend>
<input type="text" name="name" class="input w-full" required placeholder="e.g. Billable, Rush" />
</fieldset>
<fieldset class="fieldset mb-3">
<legend class="fieldset-legend text-xs">Color</legend>
<input type="color" name="color" value="#3b82f6" class="input w-full h-12 p-1" />
</fieldset>
<fieldset class="fieldset mb-4">
<legend class="fieldset-legend text-xs">Hourly Rate (cents)</legend>
<input type="number" name="rate" value="0" min="0" class="input w-full" />
<p class="text-xs text-base-content/40 mt-1">Enter rate in cents (e.g. 5000 = $50.00)</p>
</fieldset>
<div class="modal-action">
<button type="button" class="btn btn-sm" onclick="document.getElementById('new_tag_modal').close()">Cancel</button>
<button type="submit" class="btn btn-primary btn-sm">Create Tag</button>
</div>
</form>
</div>
<form method="dialog" class="modal-backdrop">
<button>close</button>
</form>
</dialog>
</DashboardLayout> </DashboardLayout>

View File

@@ -1,93 +0,0 @@
---
import DashboardLayout from '../../../../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components';
import { db } from '../../../../../../db';
import { categories, members } from '../../../../../../db/schema';
import { eq, and } from 'drizzle-orm';
const user = Astro.locals.user;
if (!user) return Astro.redirect('/login');
const { id } = Astro.params;
// Get current team from cookie
const currentTeamId = Astro.cookies.get('currentTeamId')?.value;
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const isAdmin = userMembership.role === 'owner' || userMembership.role === 'admin';
if (!isAdmin) return Astro.redirect('/dashboard/team/settings');
const category = await db.select()
.from(categories)
.where(and(
eq(categories.id, id!),
eq(categories.organizationId, userMembership.organizationId)
))
.get();
if (!category) return Astro.redirect('/dashboard/team/settings');
---
<DashboardLayout title="Edit Category - Chronus">
<div class="max-w-2xl mx-auto">
<div class="flex items-center gap-3 mb-6">
<a href="/dashboard/team/settings" class="btn btn-ghost btn-sm">
<Icon name="heroicons:arrow-left" class="w-5 h-5" />
</a>
<h1 class="text-3xl font-bold">Edit Category</h1>
</div>
<form method="POST" action={`/api/categories/${id}/update`} class="card bg-base-200 shadow-xl border border-base-300">
<div class="card-body">
<div class="form-control">
<label class="label pb-2" for="name">
<span class="label-text font-medium">Category Name</span>
</label>
<input
type="text"
id="name"
name="name"
value={category.name}
placeholder="Development"
class="input input-bordered w-full"
required
/>
</div>
<div class="form-control">
<label class="label pb-2" for="color">
<span class="label-text font-medium">Color (optional)</span>
</label>
<input
type="color"
id="color"
name="color"
value={category.color || '#3b82f6'}
class="input input-bordered w-full h-12"
/>
</div>
<div class="card-actions justify-between mt-6">
<form method="POST" action={`/api/categories/${id}/delete`}>
<button type="submit" class="btn btn-error btn-outline">Delete Category</button>
</form>
<div class="flex gap-2">
<a href="/dashboard/team/settings" class="btn btn-ghost">Cancel</a>
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</div>
</div>
</form>
</div>
</DashboardLayout>

View File

@@ -1,53 +0,0 @@
---
import DashboardLayout from '../../../../../layouts/DashboardLayout.astro';
import { Icon } from 'astro-icon/components';
const user = Astro.locals.user;
if (!user) return Astro.redirect('/login');
---
<DashboardLayout title="New Category - Chronus">
<div class="max-w-2xl mx-auto">
<div class="flex items-center gap-3 mb-6">
<a href="/dashboard/team/settings" class="btn btn-ghost btn-sm">
<Icon name="heroicons:arrow-left" class="w-5 h-5" />
</a>
<h1 class="text-3xl font-bold">Add New Category</h1>
</div>
<form method="POST" action="/api/categories/create" class="card bg-base-200 shadow-xl border border-base-300">
<div class="card-body">
<div class="form-control">
<label class="label pb-2" for="name">
<span class="label-text font-medium">Category Name</span>
</label>
<input
type="text"
id="name"
name="name"
placeholder="Development"
class="input input-bordered w-full"
required
/>
</div>
<div class="form-control">
<label class="label pb-2" for="color">
<span class="label-text font-medium">Color (optional)</span>
</label>
<input
type="color"
id="color"
name="color"
class="input input-bordered w-full h-12"
/>
</div>
<div class="card-actions justify-end mt-6">
<a href="/dashboard/team/settings" class="btn btn-ghost">Cancel</a>
<button type="submit" class="btn btn-primary">Create Category</button>
</div>
</div>
</form>
</div>
</DashboardLayout>

View File

@@ -4,27 +4,16 @@ import { Icon } from 'astro-icon/components';
import Timer from '../../components/Timer.vue'; import Timer from '../../components/Timer.vue';
import ManualEntry from '../../components/ManualEntry.vue'; import ManualEntry from '../../components/ManualEntry.vue';
import { db } from '../../db'; import { db } from '../../db';
import { timeEntries, clients, members, tags, timeEntryTags, categories, users } from '../../db/schema'; import { timeEntries, clients, tags, users } from '../../db/schema';
import { eq, desc, asc, and, sql, or, like } from 'drizzle-orm'; import { eq, desc, asc, and, sql, or, like } from 'drizzle-orm';
import { formatTimeRange } from '../../lib/formatTime'; import { formatTimeRange } from '../../lib/formatTime';
import { getCurrentTeam } from '../../lib/getCurrentTeam';
const user = Astro.locals.user; const user = Astro.locals.user;
if (!user) return Astro.redirect('/login'); if (!user) return Astro.redirect('/login');
// Get current team from cookie const userMembership = await getCurrentTeam(user, Astro.cookies.get('currentTeamId')?.value);
const currentTeamId = Astro.cookies.get('currentTeamId')?.value; if (!userMembership) return Astro.redirect('/dashboard');
const userMemberships = await db.select()
.from(members)
.where(eq(members.userId, user.id))
.all();
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
// Use current team or fallback to first membership
const userMembership = currentTeamId
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
: userMemberships[0];
const organizationId = userMembership.organizationId; const organizationId = userMembership.organizationId;
@@ -33,11 +22,6 @@ const allClients = await db.select()
.where(eq(clients.organizationId, organizationId)) .where(eq(clients.organizationId, organizationId))
.all(); .all();
const allCategories = await db.select()
.from(categories)
.where(eq(categories.organizationId, organizationId))
.all();
const allTags = await db.select() const allTags = await db.select()
.from(tags) .from(tags)
.where(eq(tags.organizationId, organizationId)) .where(eq(tags.organizationId, organizationId))
@@ -50,7 +34,7 @@ const pageSize = 20;
const offset = (page - 1) * pageSize; const offset = (page - 1) * pageSize;
const filterClient = url.searchParams.get('client') || ''; const filterClient = url.searchParams.get('client') || '';
const filterCategory = url.searchParams.get('category') || '';
const filterStatus = url.searchParams.get('status') || ''; const filterStatus = url.searchParams.get('status') || '';
const filterType = url.searchParams.get('type') || ''; const filterType = url.searchParams.get('type') || '';
const sortBy = url.searchParams.get('sort') || 'start-desc'; const sortBy = url.searchParams.get('sort') || 'start-desc';
@@ -62,10 +46,6 @@ if (filterClient) {
conditions.push(eq(timeEntries.clientId, filterClient)); conditions.push(eq(timeEntries.clientId, filterClient));
} }
if (filterCategory) {
conditions.push(eq(timeEntries.categoryId, filterCategory));
}
if (filterStatus === 'completed') { if (filterStatus === 'completed') {
conditions.push(sql`${timeEntries.endTime} IS NOT NULL`); conditions.push(sql`${timeEntries.endTime} IS NOT NULL`);
} else if (filterStatus === 'running') { } else if (filterStatus === 'running') {
@@ -107,13 +87,13 @@ switch (sortBy) {
const entries = await db.select({ const entries = await db.select({
entry: timeEntries, entry: timeEntries,
client: clients, client: clients,
category: categories,
user: users, user: users,
tag: tags,
}) })
.from(timeEntries) .from(timeEntries)
.leftJoin(clients, eq(timeEntries.clientId, clients.id)) .leftJoin(clients, eq(timeEntries.clientId, clients.id))
.leftJoin(categories, eq(timeEntries.categoryId, categories.id))
.leftJoin(users, eq(timeEntries.userId, users.id)) .leftJoin(users, eq(timeEntries.userId, users.id))
.leftJoin(tags, eq(timeEntries.tagId, tags.id))
.where(and(...conditions)) .where(and(...conditions))
.orderBy(orderBy) .orderBy(orderBy)
.limit(pageSize) .limit(pageSize)
@@ -123,9 +103,11 @@ const entries = await db.select({
const runningEntry = await db.select({ const runningEntry = await db.select({
entry: timeEntries, entry: timeEntries,
client: clients, client: clients,
tag: tags,
}) })
.from(timeEntries) .from(timeEntries)
.leftJoin(clients, eq(timeEntries.clientId, clients.id)) .leftJoin(clients, eq(timeEntries.clientId, clients.id))
.leftJoin(tags, eq(timeEntries.tagId, tags.id))
.where(and( .where(and(
eq(timeEntries.userId, user.id), eq(timeEntries.userId, user.id),
sql`${timeEntries.endTime} IS NULL` sql`${timeEntries.endTime} IS NULL`
@@ -157,24 +139,18 @@ const paginationPages = getPaginationPages(page, totalPages);
--- ---
<DashboardLayout title="Time Tracker - Chronus"> <DashboardLayout title="Time Tracker - Chronus">
<h1 class="text-3xl font-bold mb-6">Time Tracker</h1> <h1 class="text-2xl font-extrabold tracking-tight mb-6">Time Tracker</h1>
<!-- Tabs for Timer and Manual Entry --> <!-- Tabs for Timer and Manual Entry -->
<div role="tablist" class="tabs tabs-lifted mb-6"> <div class="tabs tabs-lift mb-6">
<input type="radio" name="tracker_tabs" role="tab" class="tab text-base font-medium gap-2" aria-label="Timer" checked /> <input type="radio" name="tracker_tabs" class="tab" aria-label="Timer" checked="checked" />
<div role="tabpanel" class="tab-content bg-base-100 border-base-300 rounded-box p-6"> <div class="tab-content bg-base-100 border-base-300 p-6">
{allClients.length === 0 ? ( {allClients.length === 0 ? (
<div class="alert alert-warning flex flex-col sm:flex-row items-center gap-4"> <div class="alert alert-warning flex flex-col sm:flex-row items-center gap-4">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg> <Icon name="heroicons:exclamation-triangle" class="stroke-current shrink-0 h-6 w-6" />
<span class="flex-1 text-center sm:text-left">You need to create a client before tracking time.</span> <span class="flex-1 text-center sm:text-left">You need to create a client before tracking time.</span>
<a href="/dashboard/clients/new" class="btn btn-sm btn-primary whitespace-nowrap">Add Client</a> <a href="/dashboard/clients/new" class="btn btn-sm btn-primary whitespace-nowrap">Add Client</a>
</div> </div>
) : allCategories.length === 0 ? (
<div class="alert alert-warning flex flex-col sm:flex-row items-center gap-4">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
<span class="flex-1 text-center sm:text-left">You need to create a category before tracking time.</span>
<a href="/dashboard/team/settings" class="btn btn-sm btn-primary whitespace-nowrap">Team Settings</a>
</div>
) : ( ) : (
<Timer <Timer
client:load client:load
@@ -182,34 +158,26 @@ const paginationPages = getPaginationPages(page, totalPages);
startTime: runningEntry.entry.startTime.getTime(), startTime: runningEntry.entry.startTime.getTime(),
description: runningEntry.entry.description, description: runningEntry.entry.description,
clientId: runningEntry.entry.clientId, clientId: runningEntry.entry.clientId,
categoryId: runningEntry.entry.categoryId, tagId: runningEntry.tag?.id,
} : null} } : null}
clients={allClients.map(c => ({ id: c.id, name: c.name }))} clients={allClients.map(c => ({ id: c.id, name: c.name }))}
categories={allCategories.map(c => ({ id: c.id, name: c.name, color: c.color }))}
tags={allTags.map(t => ({ id: t.id, name: t.name, color: t.color }))} tags={allTags.map(t => ({ id: t.id, name: t.name, color: t.color }))}
/> />
)} )}
</div> </div>
<input type="radio" name="tracker_tabs" role="tab" class="tab text-base font-medium gap-2" aria-label="Manual Entry" /> <input type="radio" name="tracker_tabs" class="tab" aria-label="Manual Entry" />
<div role="tabpanel" class="tab-content bg-base-100 border-base-300 rounded-box p-6"> <div class="tab-content bg-base-100 border-base-300 p-6">
{allClients.length === 0 ? ( {allClients.length === 0 ? (
<div class="alert alert-warning flex flex-col sm:flex-row items-center gap-4"> <div class="alert alert-warning flex flex-col sm:flex-row items-center gap-4">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg> <Icon name="heroicons:exclamation-triangle" class="stroke-current shrink-0 h-6 w-6" />
<span class="flex-1 text-center sm:text-left">You need to create a client before adding time entries.</span> <span class="flex-1 text-center sm:text-left">You need to create a client before adding time entries.</span>
<a href="/dashboard/clients/new" class="btn btn-sm btn-primary whitespace-nowrap">Add Client</a> <a href="/dashboard/clients/new" class="btn btn-sm btn-primary whitespace-nowrap">Add Client</a>
</div> </div>
) : allCategories.length === 0 ? (
<div class="alert alert-warning flex flex-col sm:flex-row items-center gap-4">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
<span class="flex-1 text-center sm:text-left">You need to create a category before adding time entries.</span>
<a href="/dashboard/team/settings" class="btn btn-sm btn-primary whitespace-nowrap">Team Settings</a>
</div>
) : ( ) : (
<ManualEntry <ManualEntry
client:idle client:idle
clients={allClients.map(c => ({ id: c.id, name: c.name }))} clients={allClients.map(c => ({ id: c.id, name: c.name }))}
categories={allCategories.map(c => ({ id: c.id, name: c.name, color: c.color }))}
tags={allTags.map(t => ({ id: t.id, name: t.name, color: t.color }))} tags={allTags.map(t => ({ id: t.id, name: t.name, color: t.color }))}
/> />
)} )}
@@ -221,27 +189,24 @@ const paginationPages = getPaginationPages(page, totalPages);
) : null} ) : null}
<!-- Filters and Search --> <!-- Filters and Search -->
<div class="card bg-base-200/50 backdrop-blur-sm shadow-lg border border-base-300/50 hover:border-base-300 transition-all duration-200 mb-6"> <div class="card card-border bg-base-100 mb-6">
<div class="card-body"> <div class="card-body p-4">
<form method="GET" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-6 gap-4"> <form method="GET" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-6 gap-3">
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Search</legend>
<span class="label-text font-medium">Search</span>
</label>
<input <input
type="text" type="text"
id="tracker-search"
name="search" name="search"
placeholder="Search descriptions..." placeholder="Search descriptions..."
class="input input-bordered bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors w-full" class="input w-full"
value={searchTerm} value={searchTerm}
/> />
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Client</legend>
<span class="label-text font-medium">Client</span> <select id="tracker-client" name="client" class="select w-full" onchange="this.form.submit()">
</label>
<select name="client" class="select select-bordered bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors w-full" onchange="this.form.submit()">
<option value="">All Clients</option> <option value="">All Clients</option>
{allClients.map(client => ( {allClients.map(client => (
<option value={client.id} selected={filterClient === client.id}> <option value={client.id} selected={filterClient === client.id}>
@@ -249,60 +214,40 @@ const paginationPages = getPaginationPages(page, totalPages);
</option> </option>
))} ))}
</select> </select>
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Status</legend>
<span class="label-text font-medium">Category</span> <select id="tracker-status" name="status" class="select w-full" onchange="this.form.submit()">
</label>
<select name="category" class="select select-bordered bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors w-full" onchange="this.form.submit()">
<option value="">All Categories</option>
{allCategories.map(category => (
<option value={category.id} selected={filterCategory === category.id}>
{category.name}
</option>
))}
</select>
</div>
<div class="form-control">
<label class="label">
<span class="label-text font-medium">Status</span>
</label>
<select name="status" class="select select-bordered bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors w-full" onchange="this.form.submit()">
<option value="" selected={filterStatus === ''}>All Entries</option> <option value="" selected={filterStatus === ''}>All Entries</option>
<option value="completed" selected={filterStatus === 'completed'}>Completed</option> <option value="completed" selected={filterStatus === 'completed'}>Completed</option>
<option value="running" selected={filterStatus === 'running'}>Running</option> <option value="running" selected={filterStatus === 'running'}>Running</option>
</select> </select>
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Entry Type</legend>
<span class="label-text font-medium">Entry Type</span> <select id="tracker-type" name="type" class="select w-full" onchange="this.form.submit()">
</label>
<select name="type" class="select select-bordered bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors w-full" onchange="this.form.submit()">
<option value="" selected={filterType === ''}>All Types</option> <option value="" selected={filterType === ''}>All Types</option>
<option value="timed" selected={filterType === 'timed'}>Timed</option> <option value="timed" selected={filterType === 'timed'}>Timed</option>
<option value="manual" selected={filterType === 'manual'}>Manual</option> <option value="manual" selected={filterType === 'manual'}>Manual</option>
</select> </select>
</div> </fieldset>
<div class="form-control"> <fieldset class="fieldset">
<label class="label"> <legend class="fieldset-legend text-xs">Sort By</legend>
<span class="label-text font-medium">Sort By</span> <select id="tracker-sort" name="sort" class="select w-full" onchange="this.form.submit()">
</label>
<select name="sort" class="select select-bordered bg-base-300/50 hover:bg-base-300 focus:bg-base-300 border-base-300/50 focus:border-primary transition-colors w-full" onchange="this.form.submit()">
<option value="start-desc" selected={sortBy === 'start-desc'}>Newest First</option> <option value="start-desc" selected={sortBy === 'start-desc'}>Newest First</option>
<option value="start-asc" selected={sortBy === 'start-asc'}>Oldest First</option> <option value="start-asc" selected={sortBy === 'start-asc'}>Oldest First</option>
<option value="duration-desc" selected={sortBy === 'duration-desc'}>Longest Duration</option> <option value="duration-desc" selected={sortBy === 'duration-desc'}>Longest Duration</option>
<option value="duration-asc" selected={sortBy === 'duration-asc'}>Shortest Duration</option> <option value="duration-asc" selected={sortBy === 'duration-asc'}>Shortest Duration</option>
</select> </select>
</div> </fieldset>
<input type="hidden" name="page" value="1" /> <input type="hidden" name="page" value="1" />
<div class="form-control md:col-span-2 lg:col-span-6"> <div class="flex items-end md:col-span-2 lg:col-span-1">
<button type="submit" class="btn btn-primary shadow-lg shadow-primary/20 hover:shadow-xl hover:shadow-primary/30 transition-all"> <button type="submit" class="btn btn-primary btn-sm w-full">
<Icon name="heroicons:magnifying-glass" class="w-5 h-5" /> <Icon name="heroicons:magnifying-glass" class="w-4 h-4" />
Search Search
</button> </button>
</div> </div>
@@ -310,27 +255,26 @@ const paginationPages = getPaginationPages(page, totalPages);
</div> </div>
</div> </div>
<div class="card bg-base-200/30 backdrop-blur-sm shadow-lg border border-base-300/50 hover:border-base-300 transition-all duration-200"> <div class="card card-border bg-base-100">
<div class="card-body"> <div class="card-body p-4">
<div class="flex justify-between items-center mb-4"> <div class="flex justify-between items-center mb-3">
<h2 class="card-title"> <h2 class="text-sm font-semibold flex items-center gap-2">
<Icon name="heroicons:list-bullet" class="w-6 h-6" /> <Icon name="heroicons:list-bullet" class="w-4 h-4" />
Time Entries ({totalCount?.count || 0} total) Time Entries ({totalCount?.count || 0} total)
</h2> </h2>
{(filterClient || filterCategory || filterStatus || filterType || searchTerm) && ( {(filterClient || filterStatus || filterType || searchTerm) && (
<a href="/dashboard/tracker" class="btn btn-sm btn-ghost hover:bg-base-300/50 transition-colors"> <a href="/dashboard/tracker" class="btn btn-xs btn-ghost">
<Icon name="heroicons:x-mark" class="w-4 h-4" /> <Icon name="heroicons:x-mark" class="w-3 h-3" />
Clear Filters Clear Filters
</a> </a>
)} )}
</div> </div>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table table-zebra"> <table class="table table-sm">
<thead> <thead>
<tr class="bg-base-300/30"> <tr>
<th>Type</th> <th>Type</th>
<th>Client</th> <th>Client</th>
<th>Category</th>
<th>Description</th> <th>Description</th>
<th>Member</th> <th>Member</th>
<th>Start Time</th> <th>Start Time</th>
@@ -340,35 +284,27 @@ const paginationPages = getPaginationPages(page, totalPages);
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{entries.map(({ entry, client, category, user: entryUser }) => ( {entries.map(({ entry, client, user: entryUser }) => (
<tr class="hover:bg-base-300/20 transition-colors"> <tr class="hover">
<td> <td>
{entry.isManual ? ( {entry.isManual ? (
<span class="badge badge-info badge-sm gap-1 shadow-sm" title="Manual Entry"> <span class="badge badge-info badge-xs gap-1" title="Manual Entry">
<Icon name="heroicons:pencil" class="w-3 h-3" /> <Icon name="heroicons:pencil" class="w-3 h-3" />
Manual Manual
</span> </span>
) : ( ) : (
<span class="badge badge-success badge-sm gap-1 shadow-sm" title="Timed Entry"> <span class="badge badge-success badge-xs gap-1" title="Timed Entry">
<Icon name="heroicons:clock" class="w-3 h-3" /> <Icon name="heroicons:clock" class="w-3 h-3" />
Timed Timed
</span> </span>
)} )}
</td> </td>
<td class="font-medium">{client?.name || 'Unknown'}</td> <td class="font-medium">{client?.name || 'Unknown'}</td>
<td> <td class="text-base-content/60">{entry.description || '-'}</td>
{category ? (
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full shadow-sm" style={`background-color: ${category.color}`}></span>
<span>{category.name}</span>
</div>
) : '-'}
</td>
<td class="text-base-content/80">{entry.description || '-'}</td>
<td>{entryUser?.name || 'Unknown'}</td> <td>{entryUser?.name || 'Unknown'}</td>
<td class="whitespace-nowrap"> <td class="whitespace-nowrap">
{entry.startTime.toLocaleDateString()}<br/> {entry.startTime.toLocaleDateString()}<br/>
<span class="text-xs opacity-50"> <span class="text-xs text-base-content/40">
{entry.startTime.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})} {entry.startTime.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}
</span> </span>
</td> </td>
@@ -376,23 +312,23 @@ const paginationPages = getPaginationPages(page, totalPages);
{entry.endTime ? ( {entry.endTime ? (
<> <>
{entry.endTime.toLocaleDateString()}<br/> {entry.endTime.toLocaleDateString()}<br/>
<span class="text-xs opacity-50"> <span class="text-xs text-base-content/40">
{entry.endTime.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})} {entry.endTime.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}
</span> </span>
</> </>
) : ( ) : (
<span class="badge badge-success shadow-sm">Running</span> <span class="badge badge-success badge-xs">Running</span>
)} )}
</td> </td>
<td class="font-mono font-semibold text-primary">{formatTimeRange(entry.startTime, entry.endTime)}</td> <td class="font-mono font-semibold text-primary text-sm">{formatTimeRange(entry.startTime, entry.endTime)}</td>
<td> <td>
<form method="POST" action={`/api/time-entries/${entry.id}/delete`} class="inline"> <form method="POST" action={`/api/time-entries/${entry.id}/delete`} class="inline">
<button <button
type="submit" type="submit"
class="btn btn-ghost btn-sm text-error hover:bg-error/10 transition-colors" class="btn btn-ghost btn-xs text-error"
onclick="return confirm('Are you sure you want to delete this entry?')" onclick="return confirm('Are you sure you want to delete this entry?')"
> >
<Icon name="heroicons:trash" class="w-4 h-4" /> <Icon name="heroicons:trash" class="w-3.5 h-3.5" />
</button> </button>
</form> </form>
</td> </td>
@@ -404,20 +340,20 @@ const paginationPages = getPaginationPages(page, totalPages);
<!-- Pagination --> <!-- Pagination -->
{totalPages > 1 && ( {totalPages > 1 && (
<div class="flex justify-center items-center gap-2 mt-6"> <div class="flex justify-center items-center gap-1 mt-4">
<a <a
href={`?page=${Math.max(1, page - 1)}${filterClient ? `&client=${filterClient}` : ''}${filterCategory ? `&category=${filterCategory}` : ''}${filterStatus ? `&status=${filterStatus}` : ''}${filterType ? `&type=${filterType}` : ''}${sortBy ? `&sort=${sortBy}` : ''}${searchTerm ? `&search=${searchTerm}` : ''}`} href={`?page=${Math.max(1, page - 1)}${filterClient ? `&client=${filterClient}` : ''}${filterStatus ? `&status=${filterStatus}` : ''}${filterType ? `&type=${filterType}` : ''}${sortBy ? `&sort=${sortBy}` : ''}${searchTerm ? `&search=${searchTerm}` : ''}`}
class={`btn btn-sm transition-all ${page === 1 ? 'btn-disabled' : 'hover:bg-base-300/50'}`} class={`btn btn-xs ${page === 1 ? 'btn-disabled' : ''}`}
> >
<Icon name="heroicons:chevron-left" class="w-4 h-4" /> <Icon name="heroicons:chevron-left" class="w-3 h-3" />
Previous Prev
</a> </a>
<div class="flex gap-1"> <div class="flex gap-0.5">
{paginationPages.map(pageNum => ( {paginationPages.map(pageNum => (
<a <a
href={`?page=${pageNum}${filterClient ? `&client=${filterClient}` : ''}${filterCategory ? `&category=${filterCategory}` : ''}${filterStatus ? `&status=${filterStatus}` : ''}${filterType ? `&type=${filterType}` : ''}${sortBy ? `&sort=${sortBy}` : ''}${searchTerm ? `&search=${searchTerm}` : ''}`} href={`?page=${pageNum}${filterClient ? `&client=${filterClient}` : ''}${filterStatus ? `&status=${filterStatus}` : ''}${filterType ? `&type=${filterType}` : ''}${sortBy ? `&sort=${sortBy}` : ''}${searchTerm ? `&search=${searchTerm}` : ''}`}
class={`btn btn-sm transition-all ${page === pageNum ? 'btn-active' : 'hover:bg-base-300/50'}`} class={`btn btn-xs ${page === pageNum ? 'btn-active' : ''}`}
> >
{pageNum} {pageNum}
</a> </a>
@@ -425,11 +361,11 @@ const paginationPages = getPaginationPages(page, totalPages);
</div> </div>
<a <a
href={`?page=${Math.min(totalPages, page + 1)}${filterClient ? `&client=${filterClient}` : ''}${filterCategory ? `&category=${filterCategory}` : ''}${filterStatus ? `&status=${filterStatus}` : ''}${filterType ? `&type=${filterType}` : ''}${sortBy ? `&sort=${sortBy}` : ''}${searchTerm ? `&search=${searchTerm}` : ''}`} href={`?page=${Math.min(totalPages, page + 1)}${filterClient ? `&client=${filterClient}` : ''}${filterStatus ? `&status=${filterStatus}` : ''}${filterType ? `&type=${filterType}` : ''}${sortBy ? `&sort=${sortBy}` : ''}${searchTerm ? `&search=${searchTerm}` : ''}`}
class={`btn btn-sm transition-all ${page === totalPages ? 'btn-disabled' : 'hover:bg-base-300/50'}`} class={`btn btn-xs ${page === totalPages ? 'btn-disabled' : ''}`}
> >
Next Next
<Icon name="heroicons:chevron-right" class="w-4 h-4" /> <Icon name="heroicons:chevron-right" class="w-3 h-3" />
</a> </a>
</div> </div>
)} )}

View File

@@ -7,48 +7,64 @@ if (Astro.locals.user) {
--- ---
<Layout title="Chronus - Time Tracking"> <Layout title="Chronus - Time Tracking">
<div class="hero flex-1 bg-linear-to-br from-base-100 via-base-200 to-base-300 flex items-center justify-center py-12"> <div class="flex-1 flex flex-col">
<div class="hero-content text-center"> <!-- Hero -->
<div class="max-w-4xl"> <div class="flex-1 flex items-center justify-center px-4 py-16 sm:py-24 bg-base-100">
<img src="/logo.webp" alt="Chronus Logo" class="h-24 w-24 mx-auto mb-6" /> <div class="max-w-3xl text-center">
<h1 class="text-6xl md:text-7xl font-bold mb-6 text-primary"> <img src="/logo.webp" alt="Chronus Logo" class="h-20 w-20 mx-auto mb-8" />
Chronus <h1 class="text-5xl sm:text-6xl lg:text-7xl font-extrabold tracking-tight text-base-content mb-4">
Track time,<br />
<span class="text-primary">effortlessly.</span>
</h1> </h1>
<p class="text-xl md:text-2xl py-6 text-base-content/80 font-light max-w-2xl mx-auto"> <p class="text-lg sm:text-xl text-base-content/60 max-w-xl mx-auto mb-10 leading-relaxed">
Modern time tracking designed for teams that value simplicity and precision. Modern time tracking designed for teams that value simplicity and precision.
</p> </p>
<div class="flex gap-4 justify-center mt-8 flex-wrap"> <div class="flex gap-3 justify-center flex-wrap">
<a href="/signup" class="btn btn-primary btn-lg"> <a href="/signup" class="btn btn-primary btn-lg px-8">
Get Started Get Started
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clip-rule="evenodd" /> <path fill-rule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg> </svg>
</a> </a>
<a href="/login" class="btn btn-outline btn-lg">Login</a> <a href="/login" class="btn btn-ghost btn-lg px-8">Login</a>
</div> </div>
</div>
</div>
<!-- Feature highlights --> <!-- Features -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mt-16"> <div class="bg-base-200/50 border-t border-base-200 px-4 py-16 sm:py-20">
<div class="card bg-base-100 shadow-xl hover:shadow-2xl transition-shadow"> <div class="max-w-4xl mx-auto grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="card-body items-start"> <div class="card bg-base-100 card-border">
<div class="text-4xl mb-3">⚡</div> <div class="card-body">
<h3 class="card-title text-lg">Lightning Fast</h3> <div class="w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center mb-2">
<p class="text-sm text-base-content/70">Track tasks with a single click.</p> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-primary" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z" clip-rule="evenodd" />
</svg>
</div> </div>
<h3 class="card-title text-base">Lightning Fast</h3>
<p class="text-sm text-base-content/60">Track tasks with a single click. Start, stop, and organize in seconds.</p>
</div> </div>
<div class="card bg-base-100 shadow-xl hover:shadow-2xl transition-shadow"> </div>
<div class="card-body items-start"> <div class="card bg-base-100 card-border">
<div class="text-4xl mb-3">📊</div> <div class="card-body">
<h3 class="card-title text-lg">Detailed Reports</h3> <div class="w-10 h-10 rounded-lg bg-secondary/10 flex items-center justify-center mb-2">
<p class="text-sm text-base-content/70">Get actionable insights into your team's tasks.</p> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-secondary" viewBox="0 0 20 20" fill="currentColor">
<path d="M2 11a1 1 0 011-1h2a1 1 0 011 1v5a1 1 0 01-1 1H3a1 1 0 01-1-1v-5zM8 7a1 1 0 011-1h2a1 1 0 011 1v9a1 1 0 01-1 1H9a1 1 0 01-1-1V7zM14 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1h-2a1 1 0 01-1-1V4z" />
</svg>
</div> </div>
<h3 class="card-title text-base">Detailed Reports</h3>
<p class="text-sm text-base-content/60">Get actionable insights with charts, filters, and CSV exports.</p>
</div> </div>
<div class="card bg-base-100 shadow-xl hover:shadow-2xl transition-shadow"> </div>
<div class="card-body items-start"> <div class="card bg-base-100 card-border">
<div class="text-4xl mb-3">👥</div> <div class="card-body">
<h3 class="card-title text-lg">Team Collaboration</h3> <div class="w-10 h-10 rounded-lg bg-accent/10 flex items-center justify-center mb-2">
<p class="text-sm text-base-content/70">Built for multiple team members.</p> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-accent" viewBox="0 0 20 20" fill="currentColor">
<path d="M13 6a3 3 0 11-6 0 3 3 0 016 0zM18 8a2 2 0 11-4 0 2 2 0 014 0zM14 15a4 4 0 00-8 0v3h8v-3zM6 8a2 2 0 11-4 0 2 2 0 014 0zM16 18v-3a5.972 5.972 0 00-.75-2.906A3.005 3.005 0 0119 15v3h-3zM4.75 12.094A5.973 5.973 0 004 15v3H1v-3a3 3 0 013.75-2.906z" />
</svg>
</div> </div>
<h3 class="card-title text-base">Team Collaboration</h3>
<p class="text-sm text-base-content/60">Built for teams with roles, permissions, and shared workspaces.</p>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -18,59 +18,57 @@ const errorMessage =
<Layout title="Login - Chronus"> <Layout title="Login - Chronus">
<div class="flex justify-center items-center flex-1 bg-base-100"> <div class="flex justify-center items-center flex-1 bg-base-100">
<div class="card bg-base-100 shadow-2xl w-full max-w-md mx-4"> <div class="card card-border bg-base-100 w-full max-w-sm mx-4">
<div class="card-body"> <div class="card-body gap-0">
<img src="/logo.webp" alt="Chronus" class="h-16 w-16 mx-auto mb-4" /> <img src="/logo.webp" alt="Chronus" class="h-14 w-14 mx-auto mb-3" />
<h2 class="text-3xl font-bold text-center mb-2">Welcome Back</h2> <h2 class="text-2xl font-extrabold tracking-tight text-center">Welcome Back</h2>
<p class="text-center text-base-content/60 mb-6">Sign in to continue to Chronus</p> <p class="text-center text-base-content/60 text-sm mt-1 mb-5">Sign in to continue to Chronus</p>
{errorMessage && ( {errorMessage && (
<div role="alert" class="alert alert-error mb-4"> <div role="alert" class="alert alert-error mb-4 text-sm">
<Icon name="heroicons:exclamation-circle" class="w-6 h-6" /> <Icon name="heroicons:exclamation-circle" class="w-5 h-5" />
<span>{errorMessage}</span> <span>{errorMessage}</span>
</div> </div>
)} )}
<form action="/api/auth/login" method="POST" class="space-y-4"> <form action="/api/auth/login" method="POST" class="space-y-3">
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Email</legend>
<span class="label-text font-medium">Email</span>
</div>
<input <input
type="email" type="email"
id="email"
name="email" name="email"
placeholder="your@email.com" placeholder="your@email.com"
class="input input-bordered w-full" class="input w-full"
autocomplete="email"
required required
/> />
</label> </fieldset>
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Password</legend>
<span class="label-text font-medium">Password</span>
</div>
<input <input
type="password" type="password"
id="password"
name="password" name="password"
placeholder="Enter your password" placeholder="Enter your password"
class="input input-bordered w-full" class="input w-full"
autocomplete="current-password"
required required
/> />
</label> </fieldset>
<button class="btn btn-primary w-full mt-6">Sign In</button> <button class="btn btn-primary w-full my-4">Sign In</button>
</form> </form>
<PasskeyLogin client:idle /> <PasskeyLogin client:idle />
<div class="divider">OR</div> <div class="divider text-xs">OR</div>
<div class="text-center"> <p class="text-center text-sm text-base-content/60">
<p class="text-sm text-base-content/70"> Don't have an account?
Don't have an account? <a href="/signup" class="link link-primary font-semibold">Create one</a>
<a href="/signup" class="link link-primary font-semibold">Create one</a> </p>
</p>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -34,86 +34,82 @@ const errorMessage =
<Layout title="Sign Up - Chronus"> <Layout title="Sign Up - Chronus">
<div class="flex justify-center items-center flex-1 bg-base-100"> <div class="flex justify-center items-center flex-1 bg-base-100">
<div class="card bg-base-100 shadow-2xl w-full max-w-md mx-4"> <div class="card card-border bg-base-100 w-full max-w-sm mx-4">
<div class="card-body"> <div class="card-body gap-0">
<img src="/logo.webp" alt="Chronus" class="h-16 w-16 mx-auto mb-4" /> <img src="/logo.webp" alt="Chronus" class="h-14 w-14 mx-auto mb-3" />
<h2 class="text-3xl font-bold text-center mb-2">Create Account</h2> <h2 class="text-2xl font-extrabold tracking-tight text-center">Create Account</h2>
<p class="text-center text-base-content/60 mb-6">Join Chronus to start tracking time</p> <p class="text-center text-base-content/60 text-sm mt-1 mb-5">Join Chronus to start tracking time</p>
{errorMessage && ( {errorMessage && (
<div role="alert" class="alert alert-error mb-4"> <div role="alert" class="alert alert-error mb-4 text-sm">
<Icon name="heroicons:exclamation-circle" class="w-6 h-6" /> <Icon name="heroicons:exclamation-circle" class="w-5 h-5" />
<span>{errorMessage}</span> <span>{errorMessage}</span>
</div> </div>
)} )}
{registrationDisabled ? ( {registrationDisabled ? (
<> <>
<div class="alert alert-warning"> <div class="alert alert-warning text-sm">
<Icon name="heroicons:exclamation-triangle" class="w-6 h-6" /> <Icon name="heroicons:exclamation-triangle" class="w-5 h-5" />
<span>Registration is currently disabled by the site administrator.</span> <span>Registration is currently disabled by the site administrator.</span>
</div> </div>
<div class="divider"></div> <div class="divider text-xs"></div>
<div class="text-center"> <p class="text-center text-sm text-base-content/60">
<p class="text-sm text-base-content/70"> Already have an account?
Already have an account? <a href="/login" class="link link-primary font-semibold">Sign in</a>
<a href="/login" class="link link-primary font-semibold">Sign in</a> </p>
</p>
</div>
</> </>
) : ( ) : (
<> <>
<form action="/api/auth/signup" method="POST" class="space-y-4"> <form action="/api/auth/signup" method="POST" class="space-y-3">
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Full Name</legend>
<span class="label-text font-medium">Full Name</span>
</div>
<input <input
type="text" type="text"
id="name"
name="name" name="name"
placeholder="John Doe" placeholder="John Doe"
class="input input-bordered w-full" class="input w-full"
autocomplete="name"
required required
/> />
</label> </fieldset>
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Email</legend>
<span class="label-text font-medium">Email</span>
</div>
<input <input
type="email" type="email"
id="email"
name="email" name="email"
placeholder="your@email.com" placeholder="your@email.com"
class="input input-bordered w-full" class="input w-full"
autocomplete="email"
required required
/> />
</label> </fieldset>
<label class="form-control"> <fieldset class="fieldset">
<div class="label"> <legend class="fieldset-legend text-xs">Password</legend>
<span class="label-text font-medium">Password</span>
</div>
<input <input
type="password" type="password"
id="password"
name="password" name="password"
placeholder="Create a strong password" placeholder="Create a strong password"
class="input input-bordered w-full" class="input w-full"
autocomplete="new-password"
required required
/> />
</label> </fieldset>
<button class="btn btn-primary w-full mt-6">Create Account</button> <button class="btn btn-primary w-full mt-4">Create Account</button>
</form> </form>
<div class="divider">OR</div> <div class="divider text-xs">OR</div>
<div class="text-center"> <p class="text-center text-sm text-base-content/60">
<p class="text-sm text-base-content/70"> Already have an account?
Already have an account? <a href="/login" class="link link-primary font-semibold">Sign in</a>
<a href="/login" class="link link-primary font-semibold">Sign in</a> </p>
</p>
</div>
</> </>
)} )}
</div> </div>

View File

@@ -52,10 +52,8 @@ export const GET: APIRoute = async ({ params }) => {
case ".gif": case ".gif":
contentType = "image/gif"; contentType = "image/gif";
break; break;
case ".svg": // SVG excluded to prevent stored XSS
contentType = "image/svg+xml"; // WebP omitted — not supported in PDF generation
break;
// WebP is intentionally omitted as it is not supported in PDF generation
} }
return new Response(fileContent, { return new Response(fileContent, {

View File

@@ -2,4 +2,16 @@
@plugin "daisyui" { @plugin "daisyui" {
themes: false; themes: false;
} }
@plugin "./theme.ts"; @plugin "./theme-dark.ts";
@plugin "./theme-light.ts";
/* Smoother transitions globally */
@layer base {
* {
@apply transition-colors duration-150;
}
/* Opt out for elements where color transitions are unwanted */
input, select, textarea, progress, .loading, .countdown, svg {
transition: none;
}
}

View File

@@ -0,0 +1,9 @@
import { createCatppuccinPlugin } from "@catppuccin/daisyui";
export default createCatppuccinPlugin(
"latte",
{},
{
default: false,
},
);