Skip to content

Commit a5c47d9

Browse files
committed
add i18n for valuesetform and options updated for status and navigation fix on creating new
1 parent 44c9f79 commit a5c47d9

File tree

5 files changed

+73
-68
lines changed

5 files changed

+73
-68
lines changed

public/locale/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,7 @@
19061906
"save_and_continue": "Save and Continue",
19071907
"save_investigation": "Save Investigation",
19081908
"saving": "Saving...",
1909+
"retired":"Retired",
19091910
"scan_asset_qr": "Scan Asset QR!",
19101911
"schedule": "Schedule",
19111912
"schedule_an_appointment_or_create_a_new_encounter": "Schedule an appointment or create a new encounter",
@@ -2340,6 +2341,7 @@
23402341
"valid_to": "Valid Till",
23412342
"valid_year_of_birth": "Please enter a valid year of birth (YYYY)",
23422343
"value_set": "Value Set",
2344+
"save_valuset":"Save ValueSet",
23432345
"valuesets": "Valuesets",
23442346
"vehicle_preference": "Vehicle preference",
23452347
"vendor_name": "Vendor Name",

src/components/ValueSet/ValueSetEditor.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import query from "@/Utils/request/query";
99
import {
1010
CreateValuesetModel,
1111
UpdateValuesetModel,
12-
ValuesetBase,
1312
ValuesetFormType,
1413
} from "@/types/valueset/valueset";
1514
import valuesetApi from "@/types/valueset/valuesetApi";
@@ -35,9 +34,9 @@ export function ValueSetEditor({ slug }: ValueSetEditorProps) {
3534
// Create mutation
3635
const createMutation = useMutation({
3736
mutationFn: mutate(valuesetApi.create),
38-
onSuccess: (data: ValuesetBase) => {
37+
onSuccess: () => {
3938
toast.success("ValueSet created successfully");
40-
navigate(`/valuesets/${data.slug}`);
39+
navigate(`/admin/valuesets`);
4140
},
4241
});
4342

src/components/ValueSet/ValueSetForm.tsx

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
22
import { PlusIcon, TrashIcon, UpdateIcon } from "@radix-ui/react-icons";
33
import { useMutation } from "@tanstack/react-query";
44
import { useFieldArray, useForm } from "react-hook-form";
5+
import { useTranslation } from "react-i18next";
56
import { toast } from "sonner";
67
import * as z from "zod";
78

@@ -34,59 +35,6 @@ import {
3435
import valuesetApi from "@/types/valueset/valuesetApi";
3536

3637
// 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-
});
9038

9139
interface ValueSetFormProps {
9240
initialData?: ValuesetFormType;
@@ -396,6 +344,61 @@ export function ValueSetForm({
396344
onSubmit,
397345
isSubmitting,
398346
}: 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+
});
399402
const form = useForm<ValuesetFormType>({
400403
resolver: zodResolver(valuesetFormSchema),
401404
defaultValues: {
@@ -419,7 +422,7 @@ export function ValueSetForm({
419422
name="name"
420423
render={({ field }) => (
421424
<FormItem>
422-
<FormLabel>Name</FormLabel>
425+
<FormLabel required>{t("name")}</FormLabel>
423426
<FormControl>
424427
<Input {...field} />
425428
</FormControl>
@@ -433,7 +436,7 @@ export function ValueSetForm({
433436
name="slug"
434437
render={({ field }) => (
435438
<FormItem>
436-
<FormLabel>Slug</FormLabel>
439+
<FormLabel required>{t("slug")}</FormLabel>
437440
<FormControl>
438441
<Input {...field} />
439442
</FormControl>
@@ -447,7 +450,7 @@ export function ValueSetForm({
447450
name="description"
448451
render={({ field }) => (
449452
<FormItem>
450-
<FormLabel>Description</FormLabel>
453+
<FormLabel>{t("description")}</FormLabel>
451454
<FormControl>
452455
<Textarea {...field} />
453456
</FormControl>
@@ -461,16 +464,18 @@ export function ValueSetForm({
461464
name="status"
462465
render={({ field }) => (
463466
<FormItem>
464-
<FormLabel>Status</FormLabel>
467+
<FormLabel required>{t("status")}</FormLabel>
465468
<Select onValueChange={field.onChange} defaultValue={field.value}>
466469
<FormControl>
467470
<SelectTrigger>
468-
<SelectValue placeholder="Select status" />
471+
<SelectValue placeholder="Select Status" />
469472
</SelectTrigger>
470473
</FormControl>
471474
<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>
474479
</SelectContent>
475480
</Select>
476481
<FormMessage />
@@ -484,7 +489,7 @@ export function ValueSetForm({
484489
</div>
485490

486491
<Button type="submit" disabled={isSubmitting}>
487-
{isSubmitting ? "Saving..." : "Save ValueSet"}
492+
{isSubmitting ? t("saving") : t("save_valuset")}
488493
</Button>
489494
</form>
490495
</Form>

src/components/ValueSet/ValueSetList.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function ValueSetList() {
9393
: "bg-red-100 text-red-800 hover:bg-red-200"
9494
}
9595
>
96-
{valueset.status}
96+
{t(valueset.status)}
9797
</Badge>
9898
</td>
9999
<td className="px-6 py-4">
@@ -107,12 +107,11 @@ export function ValueSetList() {
107107
<td className="whitespace-nowrap px-6 py-4 text-sm">
108108
{!valueset.is_system_defined && (
109109
<Button
110-
variant="ghost"
110+
variant="primary"
111111
size="sm"
112112
onClick={() =>
113113
navigate(`/admin/valuesets/${valueset.slug}/edit`)
114114
}
115-
className="hover:bg-primary/5"
116115
>
117116
{t("edit")}
118117
</Button>

src/types/valueset/valueset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface ValuesetBase {
2626
name: string;
2727
description: string;
2828
compose: ValuesetCompose;
29-
status: "active" | "inactive";
29+
status: "active" | "draft" | "retired" | "unknown";
3030
is_system_defined: boolean;
3131
created_by: string | null;
3232
updated_by: string | null;

0 commit comments

Comments
 (0)