PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Admin / fields / DateTimeLocalField / index.tsx

index.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Admin/fields/DateTimeLocalField/index.tsx

39 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * External dependencies
3 */
4 import {useFormContext, useFormState} from 'react-hook-form';
5
6 /**
7 * Internal dependencies
8 */
9 import {AdminSectionField} from '@givewp/components/AdminDetailsPage/AdminSection';
10 import {formatToDateTimeLocalInput, convertLocalDateTimeToISOString} from '@givewp/admin/common';
11
12 /**
13 *
14 * DateTimeLocalField component that formats the date and time to a datetime-local input and is compatible with the server-side validation date-time format RFC3339 validation.
15 *
16 * @since 4.13.0
17 */
18 export default function DateTimeLocalField({name, label}: {name: string, label: string}) {
19 const {watch, setValue} = useFormContext();
20 const {errors} = useFormState();
21 const value = watch(name);
22
23 return (
24 <AdminSectionField error={errors[name]?.message as string}>
25 <label htmlFor={name}>{label}</label>
26 <input
27 type="datetime-local"
28 id={name}
29 value={formatToDateTimeLocalInput(value)}
30 onChange={(e) => {
31 setValue(name, convertLocalDateTimeToISOString(e.target.value), {
32 shouldDirty: true,
33 });
34 }}
35 />
36 </AdminSectionField>
37 );
38 }
39