import React from "react"; import AppLayout from "@/layouts/app-layout"; import { useForm } from "@inertiajs/react"; import { Button, Card, Container, Group, Paper, SimpleGrid, Stack, Text, TextInput, Select, MultiSelect, Title, Divider, } from "@mantine/core"; import { IconArrowLeft, IconDeviceFloppy } from "@tabler/icons-react"; import { Link } from "@inertiajs/react"; import { Client } from "@/types"; interface AssignmentRole { id: number; label: string; field: "assigned_person" | "sales_person"; multiple?: boolean; } interface SelectOption { value: string; label: string; } interface AccountFormData { name: string; customer_id: string; industry: string; sql_acc_code: string; assigned_person: string[]; sales_person: string; } interface Props { id: string; client: Client; clientAssignmentRoles: AssignmentRole[]; clientAssignments: Record; assignmentUsers: SelectOption[]; } export default function Page({ id, client, clientAssignmentRoles, clientAssignments, assignmentUsers, }: Props) { const initialData: AccountFormData = { name: client.name ?? "", customer_id: client.customer_id ?? id, industry: client.industry ?? "", sql_acc_code: client.sql_acc_code ?? "", assigned_person: [], sales_person: "", }; clientAssignmentRoles.forEach((role) => { const value = clientAssignments?.[role.id]; if (role.field === "assigned_person") { initialData.assigned_person = Array.isArray(value) ? value.map(String) : value ? [String(value)] : []; return; } initialData.sales_person = value ? String(value) : ""; }); const form = useForm(initialData); const handleSubmit = (event: React.FormEvent) => { event.preventDefault(); form.transform((data) => ({ ...data, industry: data.industry || null, sql_acc_code: data.sql_acc_code || null, assigned_person: data.assigned_person .map((userId) => parseInt(userId)) .filter(Boolean), sales_person: parseInt(data.sales_person) || null, })); form.post(route("google-ads.accounts.account.update", { id })); }; return ( Edit Account
Update the foundational account info and responsible teammates. These changes are scoped to the current Google Ads account. Account Details form.setData("name", event.target.value)} error={form.errors.name} required /> form.setData("customer_id", event.target.value)} error={form.errors.customer_id} required /> form.setData("industry", event.target.value)} error={form.errors.industry} /> form.setData("sql_acc_code", event.target.value)} error={form.errors.sql_acc_code} /> ({ backgroundColor: theme.colorScheme === "dark" ? theme.colors.dark[6] : theme.white, })} > Assignments {clientAssignmentRoles.map((role) => role.multiple || role.field === "assigned_person" ? ( form.setData("assigned_person", value)} error={form.errors.assigned_person} clearable searchable /> ) : (