feat(customers): full CRUD module — pattern for all other modules
Establishes the multi-tenant module pattern. Subsequent modules (services,
software, calendar, tasks, finance, invoices) will copy this structure.
Validation:
- lib/validation/customers.ts: Zod schema with Turkish messages, optional
fields normalized to undefined.
Server actions (lib/appwrite/customer-actions.ts):
- createCustomerAction, updateCustomerAction, deleteCustomerAction
- All call requireTenant() guard, write team-scoped row permissions
(read+update by team, delete by owner|admin), and emit audit log.
- Update/delete cross-check tenantId on the existing row before mutating
(defense in depth even though row-level perms already enforce it).
- Field-level errors flattened from Zod for inline form display.
Server-side queries (lib/appwrite/customer-queries.ts):
- listCustomers(tenantId), getCustomer(tenantId, id) — admin SDK with
Query.equal('tenantId',...) tenant scope.
UI:
- /customers page (server component): pulls active tenant context, lists
customers, hands off to CustomersClient.
- CustomersClient: TanStack Table with global filter (name/email/phone/
taxId), column sorting on name + createdAt, pagination (20/page),
status badges, row actions (Edit/Delete dropdown), empty-state CTA.
- CustomerFormSheet: shadcn Sheet-based add/edit form with all fields,
toast feedback (sonner), inline field errors. Reused for create + update
by switching the action.
- DeleteCustomerDialog: confirmation modal with destructive button.
Infrastructure:
- Added sonner Toaster to root layout (richColors, closeButton).
- Updated metadata to 'İşletmem KovakCRM' and html lang='tr'.
- Renamed theme storage key to isletmem-ui-theme.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const customerSchema = z.object({
|
||||
name: z.string().trim().min(1, "İsim zorunlu.").max(255),
|
||||
email: z
|
||||
.union([z.string().email("Geçerli bir email girin."), z.literal("")])
|
||||
.optional()
|
||||
.transform((v) => (v ? v : undefined)),
|
||||
phone: z.string().trim().max(30).optional().transform((v) => (v ? v : undefined)),
|
||||
taxId: z.string().trim().max(50).optional().transform((v) => (v ? v : undefined)),
|
||||
address: z.string().trim().max(500).optional().transform((v) => (v ? v : undefined)),
|
||||
notes: z.string().trim().max(2000).optional().transform((v) => (v ? v : undefined)),
|
||||
status: z.enum(["active", "passive"]).optional().default("active"),
|
||||
});
|
||||
|
||||
export type CustomerInput = z.infer<typeof customerSchema>;
|
||||
Reference in New Issue
Block a user