@@ -2,6 +2,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
2
2
import { PlusIcon , TrashIcon , UpdateIcon } from "@radix-ui/react-icons" ;
3
3
import { useMutation } from "@tanstack/react-query" ;
4
4
import { useFieldArray , useForm } from "react-hook-form" ;
5
+ import { useTranslation } from "react-i18next" ;
5
6
import { toast } from "sonner" ;
6
7
import * as z from "zod" ;
7
8
@@ -34,59 +35,6 @@ import {
34
35
import valuesetApi from "@/types/valueset/valuesetApi" ;
35
36
36
37
// Create a schema for form validation
37
- const valuesetFormSchema = z . object ( {
38
- name : z . string ( ) . min ( 1 , "Name is required" ) ,
39
- slug : z . string ( ) . min ( 1 , "Slug is required" ) ,
40
- description : z . string ( ) ,
41
- status : z . enum ( [ "active" , "inactive" ] ) ,
42
- is_system_defined : z . boolean ( ) ,
43
- compose : z . object ( {
44
- include : z . array (
45
- z . object ( {
46
- system : z . string ( ) ,
47
- concept : z
48
- . array (
49
- z . object ( {
50
- code : z . string ( ) ,
51
- display : z . string ( ) ,
52
- } ) ,
53
- )
54
- . optional ( ) ,
55
- filter : z
56
- . array (
57
- z . object ( {
58
- property : z . string ( ) ,
59
- op : z . string ( ) ,
60
- value : z . string ( ) ,
61
- } ) ,
62
- )
63
- . optional ( ) ,
64
- } ) ,
65
- ) ,
66
- exclude : z . array (
67
- z . object ( {
68
- system : z . string ( ) ,
69
- concept : z
70
- . array (
71
- z . object ( {
72
- code : z . string ( ) ,
73
- display : z . string ( ) ,
74
- } ) ,
75
- )
76
- . optional ( ) ,
77
- filter : z
78
- . array (
79
- z . object ( {
80
- property : z . string ( ) ,
81
- op : z . string ( ) ,
82
- value : z . string ( ) ,
83
- } ) ,
84
- )
85
- . optional ( ) ,
86
- } ) ,
87
- ) ,
88
- } ) ,
89
- } ) ;
90
38
91
39
interface ValueSetFormProps {
92
40
initialData ?: ValuesetFormType ;
@@ -396,6 +344,61 @@ export function ValueSetForm({
396
344
onSubmit,
397
345
isSubmitting,
398
346
} : ValueSetFormProps ) {
347
+ const { t } = useTranslation ( ) ;
348
+
349
+ const valuesetFormSchema = z . object ( {
350
+ name : z . string ( ) . min ( 1 , t ( "field_required" ) ) ,
351
+ slug : z . string ( ) . min ( 1 , t ( "field_required" ) ) ,
352
+ description : z . string ( ) ,
353
+ status : z . enum ( [ "active" , "draft" , "retired" , "unknown" ] ) ,
354
+ is_system_defined : z . boolean ( ) ,
355
+ compose : z . object ( {
356
+ include : z . array (
357
+ z . object ( {
358
+ system : z . string ( ) ,
359
+ concept : z
360
+ . array (
361
+ z . object ( {
362
+ code : z . string ( ) ,
363
+ display : z . string ( ) ,
364
+ } ) ,
365
+ )
366
+ . optional ( ) ,
367
+ filter : z
368
+ . array (
369
+ z . object ( {
370
+ property : z . string ( ) ,
371
+ op : z . string ( ) ,
372
+ value : z . string ( ) ,
373
+ } ) ,
374
+ )
375
+ . optional ( ) ,
376
+ } ) ,
377
+ ) ,
378
+ exclude : z . array (
379
+ z . object ( {
380
+ system : z . string ( ) ,
381
+ concept : z
382
+ . array (
383
+ z . object ( {
384
+ code : z . string ( ) ,
385
+ display : z . string ( ) ,
386
+ } ) ,
387
+ )
388
+ . optional ( ) ,
389
+ filter : z
390
+ . array (
391
+ z . object ( {
392
+ property : z . string ( ) ,
393
+ op : z . string ( ) ,
394
+ value : z . string ( ) ,
395
+ } ) ,
396
+ )
397
+ . optional ( ) ,
398
+ } ) ,
399
+ ) ,
400
+ } ) ,
401
+ } ) ;
399
402
const form = useForm < ValuesetFormType > ( {
400
403
resolver : zodResolver ( valuesetFormSchema ) ,
401
404
defaultValues : {
@@ -419,7 +422,7 @@ export function ValueSetForm({
419
422
name = "name"
420
423
render = { ( { field } ) => (
421
424
< FormItem >
422
- < FormLabel > Name </ FormLabel >
425
+ < FormLabel required > { t ( "name" ) } </ FormLabel >
423
426
< FormControl >
424
427
< Input { ...field } />
425
428
</ FormControl >
@@ -433,7 +436,7 @@ export function ValueSetForm({
433
436
name = "slug"
434
437
render = { ( { field } ) => (
435
438
< FormItem >
436
- < FormLabel > Slug </ FormLabel >
439
+ < FormLabel required > { t ( "slug" ) } </ FormLabel >
437
440
< FormControl >
438
441
< Input { ...field } />
439
442
</ FormControl >
@@ -447,7 +450,7 @@ export function ValueSetForm({
447
450
name = "description"
448
451
render = { ( { field } ) => (
449
452
< FormItem >
450
- < FormLabel > Description </ FormLabel >
453
+ < FormLabel > { t ( "description" ) } </ FormLabel >
451
454
< FormControl >
452
455
< Textarea { ...field } />
453
456
</ FormControl >
@@ -461,16 +464,18 @@ export function ValueSetForm({
461
464
name = "status"
462
465
render = { ( { field } ) => (
463
466
< FormItem >
464
- < FormLabel > Status </ FormLabel >
467
+ < FormLabel required > { t ( "status" ) } </ FormLabel >
465
468
< Select onValueChange = { field . onChange } defaultValue = { field . value } >
466
469
< FormControl >
467
470
< SelectTrigger >
468
- < SelectValue placeholder = "Select status " />
471
+ < SelectValue placeholder = "Select Status " />
469
472
</ SelectTrigger >
470
473
</ FormControl >
471
474
< SelectContent >
472
- < SelectItem value = "active" > Active</ SelectItem >
473
- < SelectItem value = "inactive" > Inactive</ SelectItem >
475
+ < SelectItem value = "active" > { t ( "active" ) } </ SelectItem >
476
+ < SelectItem value = "draft" > { t ( "draft" ) } </ SelectItem >
477
+ < SelectItem value = "retired" > { t ( "retired" ) } </ SelectItem >
478
+ < SelectItem value = "unknown" > { t ( "unknown" ) } </ SelectItem >
474
479
</ SelectContent >
475
480
</ Select >
476
481
< FormMessage />
@@ -484,7 +489,7 @@ export function ValueSetForm({
484
489
</ div >
485
490
486
491
< Button type = "submit" disabled = { isSubmitting } >
487
- { isSubmitting ? "Saving..." : "Save ValueSet" }
492
+ { isSubmitting ? t ( "saving" ) : t ( "save_valuset" ) }
488
493
</ Button >
489
494
</ form >
490
495
</ Form >
0 commit comments