Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/app/(dashboard)/contracts/edit-contract-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Label, Req } from "@/components/ui/label";
import { DatePicker } from "@/components/date-picker";
import { DialogFooter } from "@/components/ui/dialog";
import { useRowDialogClose } from "@/components/row-dialog";
import { PartyCombobox } from "@/components/party-combobox";
import {
Select,
SelectContent,
Expand Down Expand Up @@ -50,8 +51,8 @@ export function EditContractForm({
footer?: React.ReactNode;
}>) {
const [state, action, pending] = useActionState(updateContract, initial);
const partyItems = Object.fromEntries(parties.map((p) => [String(p.id), p.name]));
const projectItems = Object.fromEntries(projects.map((p) => [String(p.id), p.name]));
const defaultCustomerName = parties.find((p) => p.id === contract.customerPartyId)?.name ?? "";

const close = useRowDialogClose();
useEffect(() => {
Expand Down Expand Up @@ -96,18 +97,12 @@ export function EditContractForm({

<div className="space-y-1.5">
<Label>客戶<Req /></Label>
<Select name="customerPartyId" items={partyItems} defaultValue={String(contract.customerPartyId)}>
<SelectTrigger className="w-full">
<SelectValue placeholder="選擇客戶" />
</SelectTrigger>
<SelectContent>
{parties.map((p) => (
<SelectItem key={p.id} value={String(p.id)}>
{p.name}
</SelectItem>
))}
</SelectContent>
</Select>
<PartyCombobox
parties={parties}
name="customerPartyName"
defaultName={defaultCustomerName}
placeholder="輸入或選擇客戶…"
/>
</div>
<div className="space-y-1.5">
<Label>專案</Label>
Expand Down
15 changes: 2 additions & 13 deletions src/app/(dashboard)/contracts/new-contract-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label, Req } from "@/components/ui/label";
import { DatePicker } from "@/components/date-picker";
import { PartyCombobox } from "@/components/party-combobox";
import {
Select,
SelectContent,
Expand Down Expand Up @@ -38,7 +39,6 @@ export function NewContractDialog({
}>) {
const [open, setOpen] = useState(false);
const [state, action, pending] = useActionState(createContract, initial);
const partyItems = Object.fromEntries(parties.map((p) => [String(p.id), p.name]));
const projectItems = Object.fromEntries(projects.map((p) => [String(p.id), p.name]));

useEffect(() => {
Expand Down Expand Up @@ -66,18 +66,7 @@ export function NewContractDialog({
<div className="grid gap-4 py-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label>客戶<Req /></Label>
<Select name="customerPartyId" items={partyItems}>
<SelectTrigger className="w-full">
<SelectValue placeholder="選擇客戶" />
</SelectTrigger>
<SelectContent>
{parties.map((p) => (
<SelectItem key={p.id} value={String(p.id)}>
{p.name}
</SelectItem>
))}
</SelectContent>
</Select>
<PartyCombobox parties={parties} name="customerPartyName" placeholder="輸入或選擇客戶…" />
</div>
<div className="space-y-1.5">
<Label>專案</Label>
Expand Down
25 changes: 8 additions & 17 deletions src/app/(dashboard)/projects/edit-project-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Input } from "@/components/ui/input";
import { Label, Req } from "@/components/ui/label";
import { DialogFooter } from "@/components/ui/dialog";
import { useRowDialogClose } from "@/components/row-dialog";
import { PartyCombobox } from "@/components/party-combobox";
import {
Select,
SelectContent,
Expand Down Expand Up @@ -36,7 +37,7 @@ export function EditProjectForm({
footer?: React.ReactNode;
}>) {
const [state, action, pending] = useActionState(updateProject, initial);
const partyItems = Object.fromEntries(parties.map((p) => [String(p.id), p.name]));
const defaultClientName = parties.find((p) => p.id === project.clientPartyId)?.name ?? "";

const close = useRowDialogClose();
useEffect(() => {
Expand All @@ -59,22 +60,12 @@ export function EditProjectForm({
</div>
<div className="space-y-1.5">
<Label>客戶</Label>
<Select
name="clientPartyId"
items={partyItems}
defaultValue={project.clientPartyId == null ? undefined : String(project.clientPartyId)}
>
<SelectTrigger className="w-full">
<SelectValue placeholder="— 未指定 —" />
</SelectTrigger>
<SelectContent>
{parties.map((p) => (
<SelectItem key={p.id} value={String(p.id)}>
{p.name}
</SelectItem>
))}
</SelectContent>
</Select>
<PartyCombobox
parties={parties}
name="clientPartyName"
defaultName={defaultClientName}
placeholder="輸入或選擇客戶…"
/>
</div>
<div className="space-y-1.5">
<Label>狀態</Label>
Expand Down
16 changes: 2 additions & 14 deletions src/app/(dashboard)/projects/new-project-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createProject, type ActionState } from "@/db/mutations";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label, Req } from "@/components/ui/label";
import { PartyCombobox } from "@/components/party-combobox";
import {
Select,
SelectContent,
Expand All @@ -33,8 +34,6 @@ export function NewProjectDialog({
}>) {
const [open, setOpen] = useState(false);
const [state, action, pending] = useActionState(createProject, initial);
const partyItems = Object.fromEntries(parties.map((p) => [String(p.id), p.name]));

useEffect(() => {
if (state.ok) {
setOpen(false);
Expand Down Expand Up @@ -64,18 +63,7 @@ export function NewProjectDialog({
</div>
<div className="space-y-1.5">
<Label>客戶</Label>
<Select name="clientPartyId" items={partyItems}>
<SelectTrigger className="w-full">
<SelectValue placeholder="— 未指定 —" />
</SelectTrigger>
<SelectContent>
{parties.map((p) => (
<SelectItem key={p.id} value={String(p.id)}>
{p.name}
</SelectItem>
))}
</SelectContent>
</Select>
<PartyCombobox parties={parties} name="clientPartyName" placeholder="輸入或選擇客戶…" />
</div>
<div className="space-y-1.5">
<Label>狀態</Label>
Expand Down
21 changes: 8 additions & 13 deletions src/app/(dashboard)/subscriptions/edit-subscription-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Label, Req } from "@/components/ui/label";
import { DatePicker } from "@/components/date-picker";
import { DialogFooter } from "@/components/ui/dialog";
import { useRowDialogClose } from "@/components/row-dialog";
import { PartyCombobox } from "@/components/party-combobox";
import {
Select,
SelectContent,
Expand Down Expand Up @@ -47,8 +48,8 @@ export function EditSubscriptionForm({
footer?: React.ReactNode;
}>) {
const [state, action, pending] = useActionState(updateSubscription, initial);
const partyItems = Object.fromEntries(parties.map((p) => [String(p.id), p.name]));
const projectItems = Object.fromEntries(projects.map((p) => [String(p.id), p.name]));
const defaultCustomerName = parties.find((p) => p.id === subscription.customerPartyId)?.name ?? "";

const close = useRowDialogClose();
useEffect(() => {
Expand All @@ -67,18 +68,12 @@ export function EditSubscriptionForm({

<div className="space-y-1.5">
<Label>客戶<Req /></Label>
<Select name="customerPartyId" items={partyItems} defaultValue={String(subscription.customerPartyId)}>
<SelectTrigger className="w-full">
<SelectValue placeholder="選擇客戶" />
</SelectTrigger>
<SelectContent>
{parties.map((p) => (
<SelectItem key={p.id} value={String(p.id)}>
{p.name}
</SelectItem>
))}
</SelectContent>
</Select>
<PartyCombobox
parties={parties}
name="customerPartyName"
defaultName={defaultCustomerName}
placeholder="輸入或選擇客戶…"
/>
</div>
<div className="space-y-1.5">
<Label>專案</Label>
Expand Down
15 changes: 2 additions & 13 deletions src/app/(dashboard)/subscriptions/new-subscription-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label, Req } from "@/components/ui/label";
import { DatePicker } from "@/components/date-picker";
import { PartyCombobox } from "@/components/party-combobox";
import {
Select,
SelectContent,
Expand Down Expand Up @@ -38,7 +39,6 @@ export function NewSubscriptionDialog({
}>) {
const [open, setOpen] = useState(false);
const [state, action, pending] = useActionState(createSubscription, initial);
const partyItems = Object.fromEntries(parties.map((p) => [String(p.id), p.name]));
const projectItems = Object.fromEntries(projects.map((p) => [String(p.id), p.name]));

useEffect(() => {
Expand Down Expand Up @@ -66,18 +66,7 @@ export function NewSubscriptionDialog({
<div className="grid gap-4 py-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label>客戶<Req /></Label>
<Select name="customerPartyId" items={partyItems}>
<SelectTrigger className="w-full">
<SelectValue placeholder="選擇客戶" />
</SelectTrigger>
<SelectContent>
{parties.map((p) => (
<SelectItem key={p.id} value={String(p.id)}>
{p.name}
</SelectItem>
))}
</SelectContent>
</Select>
<PartyCombobox parties={parties} name="customerPartyName" placeholder="輸入或選擇客戶…" />
</div>
<div className="space-y-1.5">
<Label>專案</Label>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(dashboard)/transactions/edit-transaction-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from "@/components/ui/select";
import { DatePicker } from "@/components/date-picker";
import { CategoryCombobox } from "./category-combobox";
import { PartyCombobox } from "./party-combobox";
import { PartyCombobox } from "@/components/party-combobox";
import { ContractCombobox, type ContractOption } from "./contract-combobox";

const initial: ActionState = { ok: false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
SheetTrigger,
} from "@/components/ui/sheet";
import { DatePicker } from "@/components/date-picker";
import { PartyCombobox } from "./party-combobox";
import { PartyCombobox } from "@/components/party-combobox";
import { CategoryCombobox } from "./category-combobox";
import { ContractCombobox, type ContractOption } from "./contract-combobox";

Expand Down
Loading