From 16c2f009c84a023145800878436d1eece973d23c Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 9 May 2025 19:16:25 +0100 Subject: [PATCH] added new invoice item schema --- shared/index.ts | 1 - .../cusModels/invoiceModels/invoiceModels.ts | 11 ++++++++++ .../invoiceModels/invoiceResponseModels.ts | 9 ++++++++ .../models/productModels/productItemModels.ts | 1 + shared/models/subModels/subModels.ts | 4 ++++ vite/src/views/customers/CustomersTable.tsx | 21 +++++++------------ .../customers/customer/InvoicesTable.tsx | 20 ++++++++++++------ vite/src/views/products/ProductRowToolbar.tsx | 1 - vite/src/views/products/ProductsTable.tsx | 17 +++++++-------- 9 files changed, 53 insertions(+), 32 deletions(-) diff --git a/shared/index.ts b/shared/index.ts index 47188de29..89336d45e 100644 --- a/shared/index.ts +++ b/shared/index.ts @@ -24,7 +24,6 @@ export * from "./models/cusModels/cusProductModels.js"; export * from "./models/cusModels/cusPriceModels/pricesInputModel.js"; export * from "./models/cusModels/cusPriceModels/cusPriceModels.js"; export * from "./models/cusModels/invoiceModels/invoiceModels.js"; -export * from "./models/cusModels/invoiceModels/invoiceItemModels.js"; export * from "./models/cusModels/cusResponseModels.js"; // Org Models diff --git a/shared/models/cusModels/invoiceModels/invoiceModels.ts b/shared/models/cusModels/invoiceModels/invoiceModels.ts index f4822274d..7162c62a4 100644 --- a/shared/models/cusModels/invoiceModels/invoiceModels.ts +++ b/shared/models/cusModels/invoiceModels/invoiceModels.ts @@ -15,6 +15,15 @@ export const InvoiceDiscountSchema = z.object({ amount_used: z.number(), }); +export const InvoiceItemSchema = z.object({ + price_id: z.string().nullish(), + stripe_id: z.string(), + internal_feature_id: z.string().nullable(), + description: z.string(), + period_start: z.number(), + period_end: z.number(), +}); + export const InvoiceSchema = z.object({ id: z.string(), created_at: z.number(), @@ -33,7 +42,9 @@ export const InvoiceSchema = z.object({ currency: z.string(), receipt_url: z.string().nullish(), discounts: z.array(InvoiceDiscountSchema), + items: z.array(InvoiceItemSchema), }); export type Invoice = z.infer; export type InvoiceDiscount = z.infer; +export type InvoiceItem = z.infer; diff --git a/shared/models/cusModels/invoiceModels/invoiceResponseModels.ts b/shared/models/cusModels/invoiceModels/invoiceResponseModels.ts index 975555efa..9d48e5a72 100644 --- a/shared/models/cusModels/invoiceModels/invoiceResponseModels.ts +++ b/shared/models/cusModels/invoiceModels/invoiceResponseModels.ts @@ -1,5 +1,14 @@ import { z } from "zod"; +export const InvoiceItemResponseSchema = z.object({ + description: z.string(), + period_start: z.number(), + period_end: z.number(), + + feature_id: z.string().optional(), + feature_name: z.string().optional(), +}); + export const InvoiceResponseSchema = z.object({ product_ids: z.array(z.string()), stripe_id: z.string(), diff --git a/shared/models/productModels/productItemModels.ts b/shared/models/productModels/productItemModels.ts index 62d7e4f7a..271460d41 100644 --- a/shared/models/productModels/productItemModels.ts +++ b/shared/models/productModels/productItemModels.ts @@ -45,6 +45,7 @@ export const ProductItemSchema = z.object({ // Feature stuff feature_id: z.string().nullish(), feature_type: z.nativeEnum(ProductItemFeatureType).nullish(), + included_usage: z.union([z.number(), z.literal(Infinite)]).nullish(), interval: z.nativeEnum(ProductItemInterval).nullish(), diff --git a/shared/models/subModels/subModels.ts b/shared/models/subModels/subModels.ts index e297c3c43..9e527fbbd 100644 --- a/shared/models/subModels/subModels.ts +++ b/shared/models/subModels/subModels.ts @@ -10,6 +10,10 @@ export const SubscriptionSchema = z.object({ // metadata: z.record(z.string(), z.any()), usage_features: z.array(z.string()), org_id: z.string(), + + current_period_start: z.number().nullable(), + current_period_end: z.number().nullable(), + env: z.nativeEnum(AppEnv), }); diff --git a/vite/src/views/customers/CustomersTable.tsx b/vite/src/views/customers/CustomersTable.tsx index 5d6920362..b39aec9bd 100644 --- a/vite/src/views/customers/CustomersTable.tsx +++ b/vite/src/views/customers/CustomersTable.tsx @@ -178,20 +178,13 @@ export const CustomersTable = ({ className="grid grid-cols-16 gap-2 items-center px-10 w-full text-sm h-8 cursor-default hover:bg-primary/5 text-t2 whitespace-nowrap" > {customer.name} - - - - {customer.id} - - - - {/* {customer.id} */} + + + {customer.id} + {customer.email} diff --git a/vite/src/views/customers/customer/InvoicesTable.tsx b/vite/src/views/customers/customer/InvoicesTable.tsx index 552a48d2c..9fcc682ab 100644 --- a/vite/src/views/customers/customer/InvoicesTable.tsx +++ b/vite/src/views/customers/customer/InvoicesTable.tsx @@ -5,6 +5,7 @@ import { Invoice, Product } from "@autumn/shared"; import { toast } from "sonner"; import { getStripeInvoiceLink } from "@/utils/linkUtils"; import { Row, Item } from "@/components/general/TableGrid"; +import { AdminHover } from "@/components/general/AdminHover"; export const InvoicesTable = () => { const { env, invoices, products, entityId, entities } = useCustomerContext(); @@ -79,12 +80,19 @@ export const InvoicesTable = () => { }} > - {invoice.product_ids - .map((p: string) => { - return products.find((product: Product) => product.id === p) - ?.name; - }) - .join(", ")} + + {invoice.product_ids + .map((p: string) => { + return products.find((product: Product) => product.id === p) + ?.name; + }) + .join(", ")} + {invoice.total.toFixed(2)} {invoice.currency.toUpperCase()} diff --git a/vite/src/views/products/ProductRowToolbar.tsx b/vite/src/views/products/ProductRowToolbar.tsx index 37d01d0f4..8fe693460 100644 --- a/vite/src/views/products/ProductRowToolbar.tsx +++ b/vite/src/views/products/ProductRowToolbar.tsx @@ -76,7 +76,6 @@ export const ProductRowToolbar = ({ setSelectedProduct(product); setDialogType("copy"); setModalOpen(true); - // await handleCopy(); }} >
diff --git a/vite/src/views/products/ProductsTable.tsx b/vite/src/views/products/ProductsTable.tsx index 77bba3877..43c5d8258 100644 --- a/vite/src/views/products/ProductsTable.tsx +++ b/vite/src/views/products/ProductsTable.tsx @@ -57,16 +57,13 @@ export const ProductsTable = ({ products }: { products: Product[] }) => { {product.name} - - - - {product.id} - - - {/* {product.id} */} + + + {product.id} +