Fix domain creation and enhance customer creation. Added more optional fields to customer creation and fixed a bug preventing domain creation when no customer was selected.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/c1009a9a-4ed8-4285-853d-b523c88c7bff.jpg
This commit is contained in:
alphaeusmote
2025-04-12 01:08:23 +00:00
parent 28de0a0c6a
commit f9ffe1f2a8
3 changed files with 267 additions and 6 deletions
+6 -1
View File
@@ -92,10 +92,14 @@ export default function DomainsPage() {
// Add domain mutation
const addDomainMutation = useMutation({
mutationFn: async (data: z.infer<typeof domainFormSchema>) => {
if (!currentCustomer?.id) {
throw new Error("No customer selected");
}
// Prepare domain data with customerId
const domainData: InsertDomain = {
...data,
customerId: currentCustomer?.id || "",
customerId: currentCustomer.id,
};
// Add special handling for providerId
@@ -106,6 +110,7 @@ export default function DomainsPage() {
}
console.log("Submitting domain with provider:", domainData.providerId);
console.log("Customer ID:", domainData.customerId);
const res = await apiRequest("POST", "/api/domains", domainData);
return await res.json();
+216 -5
View File
@@ -461,17 +461,17 @@ export default function SettingsPage() {
<Form {...createOrganizationForm}>
<form
onSubmit={createOrganizationForm.handleSubmit((data) => {
createOrganizationMutation.mutate(data);
createOrganizationForm.reset();
createCustomerMutation.mutate(data);
createCustomerForm.reset();
})}
className="space-y-4"
>
<FormField
control={createOrganizationForm.control}
control={createCustomerForm.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Customer Name</FormLabel>
<FormLabel>Customer Name*</FormLabel>
<FormControl>
<Input {...field} placeholder="Enter customer name" />
</FormControl>
@@ -481,7 +481,218 @@ export default function SettingsPage() {
/>
<FormField
control={createOrganizationForm.control}
control={createCustomerForm.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Input {...field} placeholder="Brief description of the customer" />
</FormControl>
<FormDescription>
A brief description of the customer's business
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormField
control={createCustomerForm.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input {...field} placeholder="contact@example.com" type="email" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="phone"
render={({ field }) => (
<FormItem>
<FormLabel>Phone</FormLabel>
<FormControl>
<Input {...field} placeholder="+1 (555) 123-4567" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<FormField
control={createCustomerForm.control}
name="website"
render={({ field }) => (
<FormItem>
<FormLabel>Website</FormLabel>
<FormControl>
<Input {...field} placeholder="https://example.com" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="industry"
render={({ field }) => (
<FormItem>
<FormLabel>Industry</FormLabel>
<FormControl>
<Input {...field} placeholder="Technology, Healthcare, etc." />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="space-y-1">
<h4 className="text-sm font-medium">Address Information</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormField
control={createCustomerForm.control}
name="address"
render={({ field }) => (
<FormItem>
<FormLabel>Address</FormLabel>
<FormControl>
<Input {...field} placeholder="123 Main Street" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="city"
render={({ field }) => (
<FormItem>
<FormLabel>City</FormLabel>
<FormControl>
<Input {...field} placeholder="San Francisco" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="state"
render={({ field }) => (
<FormItem>
<FormLabel>State/Province</FormLabel>
<FormControl>
<Input {...field} placeholder="CA" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="zipCode"
render={({ field }) => (
<FormItem>
<FormLabel>ZIP/Postal Code</FormLabel>
<FormControl>
<Input {...field} placeholder="94105" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="country"
render={({ field }) => (
<FormItem>
<FormLabel>Country</FormLabel>
<FormControl>
<Input {...field} placeholder="United States" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</div>
<div className="space-y-1">
<h4 className="text-sm font-medium">Billing Information</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormField
control={createCustomerForm.control}
name="billingEmail"
render={({ field }) => (
<FormItem>
<FormLabel>Billing Email</FormLabel>
<FormControl>
<Input {...field} placeholder="billing@example.com" type="email" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="billingAddress"
render={({ field }) => (
<FormItem>
<FormLabel>Billing Address</FormLabel>
<FormControl>
<Input {...field} placeholder="Same as main address or enter different address" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</div>
<FormField
control={createCustomerForm.control}
name="accountManager"
render={({ field }) => (
<FormItem>
<FormLabel>Account Manager</FormLabel>
<FormControl>
<Input {...field} placeholder="Name of assigned account manager" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="notes"
render={({ field }) => (
<FormItem>
<FormLabel>Notes</FormLabel>
<FormControl>
<Textarea {...field} placeholder="Additional notes about this customer" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={createCustomerForm.control}
name="isActive"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
+45
View File
@@ -18,8 +18,23 @@ export const users = pgTable("users", {
export const customers = pgTable("customers", {
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
description: text("description"),
email: text("email"),
phone: text("phone"),
address: text("address"),
city: text("city"),
state: text("state"),
zipCode: text("zip_code"),
country: text("country"),
website: text("website"),
industry: text("industry"),
notes: text("notes"),
accountManager: text("account_manager"),
billingEmail: text("billing_email"),
billingAddress: text("billing_address"),
isActive: boolean("is_active").default(true).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow(),
});
// Customer-User Assignment - Many-to-many relationship
@@ -182,7 +197,37 @@ export const insertUserSchema = createInsertSchema(users).pick({
export const insertCustomerSchema = createInsertSchema(customers).pick({
name: true,
description: true,
email: true,
phone: true,
address: true,
city: true,
state: true,
zipCode: true,
country: true,
website: true,
industry: true,
notes: true,
accountManager: true,
billingEmail: true,
billingAddress: true,
isActive: true,
}).extend({
// Make all fields optional except name and isActive
description: z.string().optional(),
email: z.string().email("Please enter a valid email address").optional(),
phone: z.string().optional(),
address: z.string().optional(),
city: z.string().optional(),
state: z.string().optional(),
zipCode: z.string().optional(),
country: z.string().optional(),
website: z.string().url("Please enter a valid URL").optional(),
industry: z.string().optional(),
notes: z.string().optional(),
accountManager: z.string().optional(),
billingEmail: z.string().email("Please enter a valid billing email address").optional(),
billingAddress: z.string().optional(),
});
export const insertCustomerUserAssignmentSchema = createInsertSchema(customerUserAssignments).pick({