|
1 | | -import React from "react"; |
2 | 1 | import { useParams } from "next/navigation"; |
3 | 2 | // react-hook-form |
4 | 3 | import { Controller, useForm } from "react-hook-form"; |
5 | | -// headless ui |
6 | | -import { Dialog, Transition } from "@headlessui/react"; |
7 | 4 | import { Button } from "@plane/propel/button"; |
8 | 5 | import type { IProject } from "@plane/types"; |
9 | 6 | // ui |
10 | | -import { Input } from "@plane/ui"; |
11 | | -// types |
| 7 | +import { Input, EModalPosition, EModalWidth, ModalCore } from "@plane/ui"; |
12 | 8 |
|
13 | 9 | // types |
14 | 10 | type Props = { |
@@ -43,124 +39,92 @@ export function SelectMonthModal({ type, initialValues, isOpen, handleClose, han |
43 | 39 | }; |
44 | 40 |
|
45 | 41 | return ( |
46 | | - <Transition.Root show={isOpen} as={React.Fragment}> |
47 | | - <Dialog as="div" className="relative z-30" onClose={onClose}> |
48 | | - <Transition.Child |
49 | | - as={React.Fragment} |
50 | | - enter="ease-out duration-300" |
51 | | - enterFrom="opacity-0" |
52 | | - enterTo="opacity-100" |
53 | | - leave="ease-in duration-200" |
54 | | - leaveFrom="opacity-100" |
55 | | - leaveTo="opacity-0" |
56 | | - > |
57 | | - <div className="fixed inset-0 bg-backdrop transition-opacity" /> |
58 | | - </Transition.Child> |
59 | | - |
60 | | - <div className="fixed inset-0 z-10 overflow-y-auto"> |
61 | | - <div className="flex min-h-full items-center justify-center p-4 text-center sm:p-0"> |
62 | | - <Transition.Child |
63 | | - as={React.Fragment} |
64 | | - enter="ease-out duration-300" |
65 | | - enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" |
66 | | - enterTo="opacity-100 translate-y-0 sm:scale-100" |
67 | | - leave="ease-in duration-200" |
68 | | - leaveFrom="opacity-100 translate-y-0 sm:scale-100" |
69 | | - leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" |
70 | | - > |
71 | | - <Dialog.Panel className="relative transform rounded-lg bg-surface-1 px-4 pb-4 pt-5 text-left shadow-raised-200 transition-all sm:my-8 sm:w-full sm:max-w-2xl sm:p-6"> |
72 | | - <form onSubmit={handleSubmit(onSubmit)}> |
73 | | - <div> |
74 | | - <Dialog.Title as="h3" className="text-16 font-medium leading-6 text-primary"> |
75 | | - Customize time range |
76 | | - </Dialog.Title> |
77 | | - <div className="mt-8 flex items-center gap-2"> |
78 | | - <div className="flex w-full flex-col justify-center gap-1"> |
79 | | - {type === "auto-close" ? ( |
80 | | - <> |
81 | | - <Controller |
82 | | - control={control} |
83 | | - name="close_in" |
84 | | - rules={{ |
85 | | - required: "Select a month between 1 and 12.", |
86 | | - min: 1, |
87 | | - max: 12, |
88 | | - }} |
89 | | - render={({ field: { value, onChange, ref } }) => ( |
90 | | - <div className="relative flex w-full flex-col justify-center gap-1"> |
91 | | - <Input |
92 | | - id="close_in" |
93 | | - name="close_in" |
94 | | - type="number" |
95 | | - value={value?.toString()} |
96 | | - onChange={onChange} |
97 | | - ref={ref} |
98 | | - hasError={Boolean(errors.close_in)} |
99 | | - placeholder="Enter Months" |
100 | | - className="w-full border-subtle" |
101 | | - min={1} |
102 | | - max={12} |
103 | | - /> |
104 | | - <span className="absolute right-8 top-2.5 text-13 text-secondary">Months</span> |
105 | | - </div> |
106 | | - )} |
107 | | - /> |
| 42 | + <ModalCore isOpen={isOpen} handleClose={onClose} position={EModalPosition.CENTER} width={EModalWidth.XXL}> |
| 43 | + <form onSubmit={handleSubmit(onSubmit)}> |
| 44 | + <div> |
| 45 | + <h3 className="text-16 font-medium leading-6 text-primary">Customize time range</h3> |
| 46 | + <div className="mt-8 flex items-center gap-2"> |
| 47 | + <div className="flex w-full flex-col justify-center gap-1"> |
| 48 | + {type === "auto-close" ? ( |
| 49 | + <> |
| 50 | + <Controller |
| 51 | + control={control} |
| 52 | + name="close_in" |
| 53 | + rules={{ |
| 54 | + required: "Select a month between 1 and 12.", |
| 55 | + min: 1, |
| 56 | + max: 12, |
| 57 | + }} |
| 58 | + render={({ field: { value, onChange, ref } }) => ( |
| 59 | + <div className="relative flex w-full flex-col justify-center gap-1"> |
| 60 | + <Input |
| 61 | + id="close_in" |
| 62 | + name="close_in" |
| 63 | + type="number" |
| 64 | + value={value?.toString()} |
| 65 | + onChange={onChange} |
| 66 | + ref={ref} |
| 67 | + hasError={Boolean(errors.close_in)} |
| 68 | + placeholder="Enter Months" |
| 69 | + className="w-full border-subtle" |
| 70 | + min={1} |
| 71 | + max={12} |
| 72 | + /> |
| 73 | + <span className="absolute right-8 top-2.5 text-13 text-secondary">Months</span> |
| 74 | + </div> |
| 75 | + )} |
| 76 | + /> |
108 | 77 |
|
109 | | - {errors.close_in && ( |
110 | | - <span className="px-1 text-13 text-red-500">Select a month between 1 and 12.</span> |
111 | | - )} |
112 | | - </> |
113 | | - ) : ( |
114 | | - <> |
115 | | - <Controller |
116 | | - control={control} |
117 | | - name="archive_in" |
118 | | - rules={{ |
119 | | - required: "Select a month between 1 and 12.", |
120 | | - min: 1, |
121 | | - max: 12, |
122 | | - }} |
123 | | - render={({ field: { value, onChange, ref } }) => ( |
124 | | - <div className="relative flex w-full flex-col justify-center gap-1"> |
125 | | - <Input |
126 | | - id="archive_in" |
127 | | - name="archive_in" |
128 | | - type="number" |
129 | | - value={value?.toString()} |
130 | | - onChange={onChange} |
131 | | - ref={ref} |
132 | | - hasError={Boolean(errors.archive_in)} |
133 | | - placeholder="Enter Months" |
134 | | - className="w-full border-subtle" |
135 | | - min={1} |
136 | | - max={12} |
137 | | - /> |
138 | | - <span className="absolute right-8 top-2.5 text-13 text-secondary">Months</span> |
139 | | - </div> |
140 | | - )} |
141 | | - /> |
142 | | - {errors.archive_in && ( |
143 | | - <span className="px-1 text-13 text-red-500">Select a month between 1 and 12.</span> |
144 | | - )} |
145 | | - </> |
146 | | - )} |
| 78 | + {errors.close_in && ( |
| 79 | + <span className="px-1 text-13 text-red-500">Select a month between 1 and 12.</span> |
| 80 | + )} |
| 81 | + </> |
| 82 | + ) : ( |
| 83 | + <> |
| 84 | + <Controller |
| 85 | + control={control} |
| 86 | + name="archive_in" |
| 87 | + rules={{ |
| 88 | + required: "Select a month between 1 and 12.", |
| 89 | + min: 1, |
| 90 | + max: 12, |
| 91 | + }} |
| 92 | + render={({ field: { value, onChange, ref } }) => ( |
| 93 | + <div className="relative flex w-full flex-col justify-center gap-1"> |
| 94 | + <Input |
| 95 | + id="archive_in" |
| 96 | + name="archive_in" |
| 97 | + type="number" |
| 98 | + value={value?.toString()} |
| 99 | + onChange={onChange} |
| 100 | + ref={ref} |
| 101 | + hasError={Boolean(errors.archive_in)} |
| 102 | + placeholder="Enter Months" |
| 103 | + className="w-full border-subtle" |
| 104 | + min={1} |
| 105 | + max={12} |
| 106 | + /> |
| 107 | + <span className="absolute right-8 top-2.5 text-13 text-secondary">Months</span> |
147 | 108 | </div> |
148 | | - </div> |
149 | | - </div> |
150 | | - <div className="mt-5 flex justify-end gap-2"> |
151 | | - <Button variant="secondary" size="lg" onClick={onClose}> |
152 | | - Cancel |
153 | | - </Button> |
154 | | - <Button variant="primary" size="lg" type="submit" loading={isSubmitting}> |
155 | | - {isSubmitting ? "Submitting..." : "Submit"} |
156 | | - </Button> |
157 | | - </div> |
158 | | - </form> |
159 | | - </Dialog.Panel> |
160 | | - </Transition.Child> |
| 109 | + )} |
| 110 | + /> |
| 111 | + {errors.archive_in && ( |
| 112 | + <span className="px-1 text-13 text-red-500">Select a month between 1 and 12.</span> |
| 113 | + )} |
| 114 | + </> |
| 115 | + )} |
| 116 | + </div> |
161 | 117 | </div> |
162 | 118 | </div> |
163 | | - </Dialog> |
164 | | - </Transition.Root> |
| 119 | + <div className="mt-5 flex justify-end gap-2"> |
| 120 | + <Button variant="secondary" size="lg" onClick={onClose}> |
| 121 | + Cancel |
| 122 | + </Button> |
| 123 | + <Button variant="primary" size="lg" type="submit" loading={isSubmitting}> |
| 124 | + {isSubmitting ? "Submitting..." : "Submit"} |
| 125 | + </Button> |
| 126 | + </div> |
| 127 | + </form> |
| 128 | + </ModalCore> |
165 | 129 | ); |
166 | 130 | } |
0 commit comments