@@ -34,6 +34,7 @@ import {
3434 toastManager
3535} from '@raystack/apsara' ;
3636import { useFrontier } from '~/client/contexts/FrontierContext' ;
37+ import { useTerminology , type TerminologyMap } from '../../../hooks/useTerminology' ;
3738import { DEFAULT_DATE_FORMAT } from '~/client/utils/constants' ;
3839import { usePermissions } from '~/client/hooks/usePermissions' ;
3940import { PERMISSIONS , shouldShowComponent } from '../../../../utils' ;
@@ -51,31 +52,37 @@ const ORG_UPDATE_PERMISSION = `${PERMISSIONS.OrganizationNamespace.replace(
5152const roleGrantsOrgUpdate = ( role : Role ) =>
5253 role . permissions ?. includes ( ORG_UPDATE_PERMISSION ) ?? false ;
5354
54- const baseFields = {
55+ const getBaseFields = ( t : TerminologyMap ) => ( {
5556 title : yup . string ( ) . required ( 'Name is required' ) ,
56- orgRoleId : yup . string ( ) . required ( 'Organization role is required' ) ,
57- projectRoleId : yup . string ( ) . required ( 'Project role is required' ) ,
57+ orgRoleId : yup
58+ . string ( )
59+ . required ( `${ t . organization ( { case : 'capital' } ) } role is required` ) ,
60+ projectRoleId : yup
61+ . string ( )
62+ . required ( `${ t . project ( { case : 'capital' } ) } role is required` ) ,
5863 projectIds : yup
5964 . array ( )
6065 . of ( yup . string ( ) . required ( ) )
6166 . default ( [ ] )
62- } ;
63-
64- const createPATSchema = yup
65- . object ( {
66- ...baseFields ,
67- expiry : yup . string ( ) . required ( 'Expiry date is required' )
68- } )
69- . required ( ) ;
70-
71- const updatePATSchema = yup
72- . object ( {
73- ...baseFields ,
74- expiry : yup . string ( ) . default ( '' )
75- } )
76- . required ( ) ;
77-
78- type FormData = yup . InferType < typeof createPATSchema > ;
67+ } ) ;
68+
69+ const getCreatePATSchema = ( t : TerminologyMap ) =>
70+ yup
71+ . object ( {
72+ ...getBaseFields ( t ) ,
73+ expiry : yup . string ( ) . required ( 'Expiry date is required' )
74+ } )
75+ . required ( ) ;
76+
77+ const getUpdatePATSchema = ( t : TerminologyMap ) =>
78+ yup
79+ . object ( {
80+ ...getBaseFields ( t ) ,
81+ expiry : yup . string ( ) . default ( '' )
82+ } )
83+ . required ( ) ;
84+
85+ type FormData = yup . InferType < ReturnType < typeof getCreatePATSchema > > ;
7986
8087export interface PATFormDialogProps {
8188 handle : ReturnType < typeof Dialog . createHandle > ;
@@ -91,11 +98,17 @@ export function PATFormDialog({
9198 onUpdated
9299} : PATFormDialogProps ) {
93100 const { activeOrganization : organization , config } = useFrontier ( ) ;
101+ const t = useTerminology ( ) ;
94102 const orgId = organization ?. id || '' ;
95103 const dateFormat = config ?. dateFormat || DEFAULT_DATE_FORMAT ;
96104
97105 const isUpdateMode = Boolean ( initialData ) ;
98106
107+ const patSchema = useMemo (
108+ ( ) => ( isUpdateMode ? getUpdatePATSchema ( t ) : getCreatePATSchema ( t ) ) ,
109+ [ t , isUpdateMode ]
110+ ) ;
111+
99112 const {
100113 register,
101114 control,
@@ -108,7 +121,7 @@ export function PATFormDialog({
108121 clearErrors,
109122 formState : { errors, isSubmitting, isDirty }
110123 } = useForm < FormData > ( {
111- resolver : yupResolver ( isUpdateMode ? updatePATSchema : createPATSchema ) ,
124+ resolver : yupResolver ( patSchema ) ,
112125 defaultValues : {
113126 title : '' ,
114127 expiry : '' ,
@@ -292,7 +305,7 @@ export function PATFormDialog({
292305 ) {
293306 setError ( 'projectIds' , {
294307 type : 'manual' ,
295- message : ' At least one project is required'
308+ message : ` At least one ${ t . project ( { case : 'lower' } ) } is required`
296309 } ) ;
297310 return ;
298311 }
@@ -479,7 +492,7 @@ export function PATFormDialog({
479492 ) }
480493
481494 < Flex direction = "column" gap = { 2 } >
482- < Label > Organization Role</ Label >
495+ < Label > { t . organization ( { case : 'capital' } ) } Role</ Label >
483496 < Controller
484497 name = "orgRoleId"
485498 control = { control }
@@ -509,7 +522,7 @@ export function PATFormDialog({
509522 </ Flex >
510523
511524 < Flex direction = "column" gap = { 2 } >
512- < Label > Project Role</ Label >
525+ < Label > { t . project ( { case : 'capital' } ) } Role</ Label >
513526 < Controller
514527 name = "projectRoleId"
515528 control = { control }
@@ -540,7 +553,7 @@ export function PATFormDialog({
540553
541554 < Flex direction = "column" gap = { 5 } >
542555 < Flex direction = "column" gap = { 4 } >
543- < Label > Projects </ Label >
556+ < Label > { t . project ( { case : 'capital' , plural : true } ) } </ Label >
544557 < Radio . Group
545558 value = { projectAccess }
546559 onValueChange = { ( val : string ) => {
@@ -570,7 +583,7 @@ export function PATFormDialog({
570583 disabled = { isOrgAdmin }
571584 />
572585 < Text size = "small" variant = "secondary" >
573- Selective projects
586+ Selective { t . project ( { case : 'lower' , plural : true } ) }
574587 </ Text >
575588 </ Flex >
576589 </ Flex >
@@ -598,7 +611,9 @@ export function PATFormDialog({
598611 } }
599612 >
600613 < Select . Trigger >
601- < Select . Value placeholder = "Select projects" >
614+ < Select . Value
615+ placeholder = { `Select ${ t . project ( { case : 'lower' , plural : true } ) } ` }
616+ >
602617 { selectedIds . length === 0 ? null : (
603618 < Flex gap = { 2 } align = "center" >
604619 { visible . map ( id => (
0 commit comments