feat(frontend): add test deps, VAT types, and business info store
Add jsdom and vitest dev dependencies. Add total_vat_amount and total_net_amount to PaymentSummary type. Create shared businessInfo store for caching public business settings. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// src/lib/stores/businessInfo.svelte.ts
|
||||
import type { BusinessSettings } from '$lib/types/settings';
|
||||
|
||||
let businessInfo = $state<BusinessSettings | null>(null);
|
||||
let loadingPromise: Promise<BusinessSettings | null> | null = null;
|
||||
|
||||
/**
|
||||
* Fetches /api/business-info exactly once and caches the result.
|
||||
* Subsequent calls return the cached promise or resolved value.
|
||||
* Errors are handled gracefully — returns null.
|
||||
*/
|
||||
export async function ensureBusinessInfo(): Promise<BusinessSettings | null> {
|
||||
if (businessInfo !== null) return businessInfo;
|
||||
if (loadingPromise) return loadingPromise;
|
||||
|
||||
loadingPromise = fetch('/api/business-info')
|
||||
.then((r) => (r.ok ? r.json() : null))
|
||||
.then((data) => {
|
||||
businessInfo = data as BusinessSettings | null;
|
||||
return businessInfo;
|
||||
})
|
||||
.catch(() => {
|
||||
businessInfo = null;
|
||||
return null;
|
||||
});
|
||||
|
||||
return loadingPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current cached business info (reactive via $state).
|
||||
* Use in $derived or $effect to track changes.
|
||||
*/
|
||||
export function getBusinessInfo(): BusinessSettings | null {
|
||||
return businessInfo;
|
||||
}
|
||||
@@ -48,6 +48,8 @@ export interface PaymentSummary {
|
||||
paid_amount: number;
|
||||
refunded_amount: number;
|
||||
remaining_amount: number;
|
||||
total_vat_amount: number;
|
||||
total_net_amount: number;
|
||||
payments: Payment[];
|
||||
refunds: Refund[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user