create.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {
  2. Form,
  3. Input,
  4. Button,
  5. } from "antd";
  6. import { Create, useForm } from "@refinedev/antd";
  7. import { Card } from "antd";
  8. import { ClientFormData } from "../../types/client";
  9. export const ClientCreate = () => {
  10. const { formProps, saveButtonProps, form } = useForm<ClientFormData>({
  11. redirect: "list",
  12. onMutationSuccess: (data) => {
  13. console.log("Client created successfully:", data);
  14. },
  15. onMutationError: (error) => {
  16. console.error("Error creating client:", error);
  17. },
  18. });
  19. const fillTestData = () => {
  20. form?.setFieldsValue({
  21. name: "Test Client",
  22. contactEmail: "test@example.com",
  23. organization: "Test Organization"
  24. });
  25. };
  26. return (
  27. <Create
  28. saveButtonProps={saveButtonProps}
  29. headerButtons={[
  30. <Button key="test-data" onClick={fillTestData} type="dashed">
  31. Fill Test Data
  32. </Button>
  33. ]}
  34. >
  35. <Form {...formProps} layout="vertical">
  36. <Card title="Client Information">
  37. <Form.Item
  38. label="Name"
  39. name="name"
  40. rules={[
  41. {
  42. required: true,
  43. message: "Please enter client name",
  44. },
  45. ]}
  46. >
  47. <Input placeholder="Client name" />
  48. </Form.Item>
  49. <Form.Item
  50. label="Contact Email"
  51. name="contactEmail"
  52. rules={[
  53. {
  54. required: true,
  55. type: "email",
  56. message: "Please enter a valid email address",
  57. },
  58. ]}
  59. >
  60. <Input placeholder="contact@example.com" />
  61. </Form.Item>
  62. <Form.Item
  63. label="Organization"
  64. name="organization"
  65. rules={[
  66. {
  67. required: true,
  68. message: "Please enter organization name",
  69. },
  70. ]}
  71. >
  72. <Input placeholder="Organization name" />
  73. </Form.Item>
  74. </Card>
  75. </Form>
  76. </Create>
  77. );
  78. };