-
Notifications
You must be signed in to change notification settings - Fork 122
/
TargetCustomerForm.tsx
80 lines (74 loc) · 2.32 KB
/
TargetCustomerForm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { useState } from "react";
import { Form, Modal, Select } from "antd";
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import { Customer } from "../../api/api";
import { CustomerPlus } from "../../types/customer-type";
const { Option } = Select;
interface Props {
visible: boolean;
onCancel: () => void;
onAddTargetCustomer: (target_customer_id: string) => void;
}
function TargetCustomerForm({ ...props }: Props) {
const [form] = Form.useForm();
const [targetCustomer, setTargetCustomer] = useState<string>(""); // id of the target customer
const { data: customers }: UseQueryResult<CustomerPlus[]> = useQuery<
CustomerPlus[]
>(["customer_list"], () => Customer.getCustomers().then((res) => res));
return (
<Form.Provider>
<Form
form={form}
name="target_customer_form"
layout="vertical"
initialValues={{
target_customer: targetCustomer,
}}
onFinish={() => {
props.onAddTargetCustomer(targetCustomer);
}}
>
<Modal
visible={props.visible}
title="Choose Target Customer For Plan"
okText="Confirm and Create Plan"
okType="default"
okButtonProps={{
type: "primary",
}}
onCancel={props.onCancel}
onOk={() => {
form.submit();
}}
>
<div className="grid grid-row-3">
<div className="flex flex-col">
<Form.Item
name="target_customer"
label="Customer"
rules={[{ required: true }]}
>
<Select
placeholder="Choose Customer"
showSearch
onChange={(value) => {
setTargetCustomer(value);
}} // id of the target customer)}
>
{React.Children.toArray(
customers?.map((customer) => (
<Option value={customer.customer_id}>
{customer.customer_name}
</Option>
))
)}
</Select>
</Form.Item>
</div>
</div>
</Modal>
</Form>
</Form.Provider>
);
}
export default TargetCustomerForm;