1
1
import { ChangeEvent , useEffect , useState } from "react" ;
2
2
3
+ import { Temporal } from "temporal-polyfill" ;
4
+
3
5
import { IPFS_NEAR_SOCIAL_URL } from "@/common/constants" ;
4
6
import { Campaign } from "@/common/contracts/core/campaigns" ;
5
7
import { yoctoNearToFloat } from "@/common/lib" ;
@@ -11,12 +13,6 @@ import { NearInputField } from "@/entities/_shared";
11
13
12
14
import { useCampaignForm } from "../hooks/forms" ;
13
15
14
- const formatTimestampForInput = ( timestamp : number ) => {
15
- if ( ! timestamp ) return "" ;
16
- const date = new Date ( timestamp ) ;
17
- return date . toISOString ( ) . slice ( 0 , 16 ) ;
18
- } ;
19
-
20
16
export const CampaignForm = ( {
21
17
existingData,
22
18
campaignId,
@@ -50,17 +46,13 @@ export const CampaignForm = ({
50
46
form . setValue ( "max_amount" , yoctoNearToFloat ( existingData . max_amount ) ) ;
51
47
}
52
48
53
- form . setValue (
54
- "start_ms" ,
55
- existingData ?. start_ms ? formatTimestampForInput ( existingData ?. start_ms ) : "" ,
56
- ) ;
49
+ form . setValue ( "start_ms" , existingData ?. start_ms ) ;
57
50
58
- form . setValue (
59
- "end_ms" ,
60
- existingData ?. end_ms ? formatTimestampForInput ( existingData ?. end_ms ) : "" ,
61
- ) ;
51
+ if ( existingData ?. end_ms ) {
52
+ form . setValue ( "end_ms" , existingData ?. end_ms ) ;
53
+ }
62
54
}
63
- } , [ isUpdate , existingData , form ] ) ;
55
+ } , [ isUpdate , existingData ] ) ;
64
56
65
57
const handleCoverImageChange = async ( e : ChangeEvent ) => {
66
58
const target = e . target as HTMLInputElement ;
@@ -209,11 +201,19 @@ export const CampaignForm = ({
209
201
< FormField
210
202
control = { form . control }
211
203
name = "start_ms"
212
- render = { ( { field } ) => (
204
+ render = { ( { field : { value , ... field } } ) => (
213
205
< TextField
214
- label = "Start Date"
215
206
{ ...field }
216
- required
207
+ required = { ! ! watch ( "min_amount" ) }
208
+ label = "Start Date"
209
+ value = {
210
+ typeof value === "number"
211
+ ? Temporal . Instant . fromEpochMilliseconds ( value )
212
+ . toZonedDateTimeISO ( Temporal . Now . timeZoneId ( ) )
213
+ . toPlainDateTime ( )
214
+ . toString ( { smallestUnit : "minute" } )
215
+ : undefined
216
+ }
217
217
classNames = { { root : "lg:w-90" } }
218
218
type = "datetime-local"
219
219
/>
@@ -222,11 +222,19 @@ export const CampaignForm = ({
222
222
< FormField
223
223
control = { form . control }
224
224
name = "end_ms"
225
- render = { ( { field } ) => (
225
+ render = { ( { field : { value , ... field } } ) => (
226
226
< TextField
227
+ { ...field }
227
228
required = { ! ! watch ( "min_amount" ) }
228
229
label = "End Date"
229
- { ...field }
230
+ value = {
231
+ typeof value === "number"
232
+ ? Temporal . Instant . fromEpochMilliseconds ( value )
233
+ . toZonedDateTimeISO ( Temporal . Now . timeZoneId ( ) )
234
+ . toPlainDateTime ( )
235
+ . toString ( { smallestUnit : "minute" } )
236
+ : undefined
237
+ }
230
238
classNames = { { root : "lg:w-90" } }
231
239
type = "datetime-local"
232
240
/>
0 commit comments