@@ -110,6 +110,7 @@ export default function Details() {
110
110
register,
111
111
handleSubmit,
112
112
control,
113
+ reset,
113
114
formState : { errors } ,
114
115
} = useForm < UpdateStateActivities > ( ) ;
115
116
@@ -307,7 +308,10 @@ export default function Details() {
307
308
bgColor = { "#185C99" }
308
309
borderRadius = { "full" }
309
310
_hover = { { bgColor : "#295278" } }
310
- onClick = { onOpen }
311
+ onClick = { ( ) => {
312
+ reset ( ) ;
313
+ onOpen ( ) ;
314
+ } }
311
315
>
312
316
< Flex alignItems = { "center" } color = { "white" } >
313
317
< Icon as = { MdEdit } boxSize = { 4 } />
@@ -431,19 +435,28 @@ export default function Details() {
431
435
< Modal size = { "2xl" } onClose = { onClose } isOpen = { isOpen } isCentered >
432
436
< ModalOverlay />
433
437
< ModalContent borderRadius = { "xl" } >
438
+ < ModalHeader > Sunting STATE { dataState ?. name } </ ModalHeader >
439
+ < ModalCloseButton />
440
+
434
441
< form
435
442
// to handle multipart, please use formData :)
436
443
onSubmit = { handleSubmit ( ( data ) => {
437
444
const formData = new FormData ( ) ;
438
- formData . append ( "name" , data . name ) ;
439
- formData . append ( "day" , data . day ) ;
445
+ formData . append ( "name" , data . name ?? dataState ?. name ) ;
446
+ formData . append ( "day" , data . day ?? dataState ?. day ) ;
440
447
formData . append ( "stateDesc" , data . stateDesc ) ;
441
- formData . append ( "location" , data . location ) ;
442
- formData . append ( "quota" , data . quota . toString ( ) ) ;
443
- formData . append ( "test_file" , data . stateLogo ) ;
448
+ formData . append ( "location" , data . location ?? dataState ?. location ) ;
449
+ formData . append (
450
+ "quota" ,
451
+ data . quota ? data . quota . toString ( ) : dataState ! . quota . toString ( )
452
+ ) ;
453
+
454
+ if ( data . stateLogo ) {
455
+ formData . append ( "test_file" , data . stateLogo ) ;
456
+ }
444
457
445
458
api
446
- . put ( `/stateAct/update/` , formData , {
459
+ . put ( `/stateAct/update/${ params . stateID } ` , formData , {
447
460
headers : {
448
461
"Content-Type" : "multipart/form-data" ,
449
462
} ,
@@ -460,86 +473,84 @@ export default function Details() {
460
473
onClose ( ) ;
461
474
} ) }
462
475
>
463
- < ModalBody >
464
- < Center w = { "full" } my = { "1em" } >
465
- < Text fontSize = { "2xl" } fontWeight = { "semibold" } color = { "#11D22" } >
466
- Sunting
467
- </ Text >
468
- </ Center >
469
- < Box w = { "full" } >
470
- < ModalBody textColor = "#1e1d22" >
471
- < FormControl isInvalid = { ! ! errors . stateLogo } >
472
- < Box w = { "full" } mb = { "2em" } >
473
- < FormLabel
474
- fontSize = { "md" }
475
- fontWeight = { "semibold" }
476
- color = { "#11D22" }
477
- >
478
- Logo
479
- </ FormLabel >
480
-
481
- < Box
482
- padding = { "1em" }
483
- border = { "solid #CBD5E0" }
484
- width = { "100%" }
485
- height = { "100%" }
486
- borderRadius = { 10 }
487
- transition = { "0.1s ease-in-out" }
488
- _hover = { { border : "solid #CBD5E0" } }
489
- >
490
- < DropZone
491
- control = { control }
492
- name = "stateLogo"
493
- rules = { {
494
- required : "Logo STATE tidak boleh kosong." ,
495
- } }
496
- />
497
- { /* <Input
476
+ < ModalBody textColor = "#1e1d22" >
477
+ < FormControl isInvalid = { ! ! errors . stateLogo } >
478
+ < Box w = { "full" } mb = { "2em" } >
479
+ < FormLabel
480
+ fontSize = { "md" }
481
+ fontWeight = { "semibold" }
482
+ color = { "#11D22" }
483
+ >
484
+ Ganti Logo
485
+ </ FormLabel >
486
+
487
+ < Box
488
+ padding = { "1em" }
489
+ border = { "solid #CBD5E0" }
490
+ width = { "100%" }
491
+ height = { "100%" }
492
+ borderRadius = { 10 }
493
+ transition = { "0.1s ease-in-out" }
494
+ _hover = { { border : "solid #CBD5E0" } }
495
+ >
496
+ < DropZone
497
+ control = { control }
498
+ name = "stateLogo"
499
+ defaultValue = { dataState ?. stateLogo }
500
+ // rules={{
501
+ // required: "Logo STATE tidak boleh kosong.",
502
+ // }}
503
+ />
504
+ { /* <Input
498
505
id="stateLogo"
499
506
type="file"
500
507
{...register("stateLogo", {
501
508
required: "Logo STATE tidak boleh kosong.",
502
509
})}
503
510
/> */ }
504
- </ Box >
505
- < FormErrorMessage >
506
- { errors . stateLogo && errors . stateLogo . message }
507
- </ FormErrorMessage >
508
- </ Box >
509
- </ FormControl >
511
+ </ Box >
512
+ < FormErrorMessage >
513
+ { errors . stateLogo && errors . stateLogo . message }
514
+ </ FormErrorMessage >
515
+ </ Box >
516
+ </ FormControl >
510
517
511
- < FormControl isInvalid = { ! ! errors . name } >
512
- < FormLabel > Name</ FormLabel >
513
- < Input
514
- id = "name"
515
- { ...register ( "name" , {
516
- value : dataState ?. name ,
517
- required : "Nama STATE tidak boleh kosong." ,
518
- pattern : {
519
- value : / ^ [ A - Z a - z . ] * $ / ,
520
- message : "Nama STATE tidak valid" ,
521
- } ,
522
- } ) }
523
- />
524
- < FormErrorMessage >
525
- { errors . name && errors . name . message }
526
- </ FormErrorMessage >
527
- </ FormControl >
518
+ { auth . role !== "organisator" && (
519
+ < FormControl isInvalid = { ! ! errors . name } >
520
+ < FormLabel > Name</ FormLabel >
521
+ < Input
522
+ id = "name"
523
+ { ...register ( "name" , {
524
+ value : dataState ?. name ,
525
+ required : "Nama STATE tidak boleh kosong." ,
526
+ pattern : {
527
+ value : / ^ [ A - Z a - z . ] * $ / ,
528
+ message : "Nama STATE tidak valid" ,
529
+ } ,
530
+ } ) }
531
+ />
532
+ < FormErrorMessage >
533
+ { errors . name && errors . name . message }
534
+ </ FormErrorMessage >
535
+ </ FormControl >
536
+ ) }
528
537
529
- < FormControl isInvalid = { ! ! errors . stateDesc } >
530
- < FormLabel > Deksripsi</ FormLabel >
531
- < Textarea
532
- id = "stateDesc"
533
- { ...register ( "stateDesc" , {
534
- value : dataState ?. stateDesc ,
535
- required : "Deskripsi STATE tidak boleh kosong" ,
536
- } ) }
537
- />
538
- < FormErrorMessage >
539
- { errors . stateDesc && errors . stateDesc . message }
540
- </ FormErrorMessage >
541
- </ FormControl >
538
+ < FormControl isInvalid = { ! ! errors . stateDesc } >
539
+ < FormLabel > Deksripsi</ FormLabel >
540
+ < Textarea
541
+ id = "stateDesc"
542
+ { ...register ( "stateDesc" , {
543
+ value : dataState ?. stateDesc ,
544
+ required : "Deskripsi STATE tidak boleh kosong" ,
545
+ } ) }
546
+ />
547
+ < FormErrorMessage >
548
+ { errors . stateDesc && errors . stateDesc . message }
549
+ </ FormErrorMessage >
550
+ </ FormControl >
542
551
552
+ { auth . role !== "organisator" && (
553
+ < >
543
554
< FormControl isInvalid = { ! ! errors . location } >
544
555
< FormLabel > Lokasi</ FormLabel >
545
556
< Input
@@ -600,8 +611,8 @@ export default function Details() {
600
611
{ errors . quota && errors . quota . message }
601
612
</ FormErrorMessage >
602
613
</ FormControl >
603
- </ ModalBody >
604
- </ Box >
614
+ </ >
615
+ ) }
605
616
</ ModalBody >
606
617
< ModalFooter >
607
618
< Button type = "submit" color = "#185C99" mr = { 3 } >
0 commit comments