Skip to content

Commit e829b65

Browse files
feat: update pat terminology (#1721)
1 parent 9c2795d commit e829b65

3 files changed

Lines changed: 55 additions & 32 deletions

File tree

‎web/sdk/client/views/pat/components/pat-form-dialog.tsx‎

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
toastManager
3535
} from '@raystack/apsara';
3636
import { useFrontier } from '~/client/contexts/FrontierContext';
37+
import { useTerminology, type TerminologyMap } from '../../../hooks/useTerminology';
3738
import { DEFAULT_DATE_FORMAT } from '~/client/utils/constants';
3839
import { usePermissions } from '~/client/hooks/usePermissions';
3940
import { PERMISSIONS, shouldShowComponent } from '../../../../utils';
@@ -51,31 +52,37 @@ const ORG_UPDATE_PERMISSION = `${PERMISSIONS.OrganizationNamespace.replace(
5152
const 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

8087
export 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 => (

‎web/sdk/client/views/pat/components/pat-project-chips.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useLayoutEffect, useRef, useState } from 'react';
44
import { Chip } from '@raystack/apsara';
5+
import { useTerminology } from '../../../hooks/useTerminology';
56
import styles from './pat-project-chips.module.css';
67

78
interface ProjectChipItem {
@@ -18,6 +19,7 @@ const COUNT_CHIP_WIDTH_RESERVE = 56;
1819
const CHIP_GAP = 4;
1920

2021
export function PATProjectChips({ projects }: PATProjectChipsProps) {
22+
const t = useTerminology();
2123
const [expanded, setExpanded] = useState(false);
2224
const [visibleCount, setVisibleCount] = useState<number | null>(null);
2325
const containerRef = useRef<HTMLDivElement>(null);
@@ -69,7 +71,7 @@ export function PATProjectChips({ projects }: PATProjectChipsProps) {
6971
<Chip
7072
className={styles.countChip}
7173
onClick={() => setExpanded(true)}
72-
aria-label={`Show ${hidden} more projects`}
74+
aria-label={`Show ${hidden} more ${t.project({ case: 'lower', plural: true })}`}
7375
data-test-id="frontier-sdk-pat-project-chips-expand-btn"
7476
>
7577
+{hidden}

‎web/sdk/client/views/pat/pat-details-view.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
} from './components/regenerate-pat-dialog';
5050
import { RevokePATDialog } from './components/revoke-pat-dialog';
5151
import { getExpiryOptionValue, getExpiryReferenceDayjs } from './utils';
52+
import { useTerminology } from '../../hooks/useTerminology';
5253
import styles from './pat-details-view.module.css';
5354

5455
dayjs.extend(relativeTime);
@@ -93,6 +94,7 @@ export function PATDetailsView({
9394
onDeleteSuccess
9495
}: PATDetailsViewProps) {
9596
const { activeOrganization: organization, config } = useFrontier();
97+
const t = useTerminology();
9698
const orgId = organization?.id || '';
9799
const dateFormat = config?.dateFormat || DEFAULT_DATE_FORMAT;
98100

@@ -363,15 +365,19 @@ export function PATDetailsView({
363365
{createdOn && <DetailRow label="Created on:">{createdOn}</DetailRow>}
364366
{lastUsed && <DetailRow label="Last used:">{lastUsed}</DetailRow>}
365367
{orgRoleName && (
366-
<DetailRow label="Organization role:">{orgRoleName}</DetailRow>
368+
<DetailRow label={`${t.organization({ case: 'capital' })} role:`}>
369+
{orgRoleName}
370+
</DetailRow>
367371
)}
368372
{projectRoleName && (
369-
<DetailRow label="Project role:">{projectRoleName}</DetailRow>
373+
<DetailRow label={`${t.project({ case: 'capital' })} role:`}>
374+
{projectRoleName}
375+
</DetailRow>
370376
)}
371-
<DetailRow label="Projects:">
377+
<DetailRow label={`${t.project({ case: 'capital', plural: true })}:`}>
372378
{isAllProjects || scopeProjects.length === 0 ? (
373379
<Text size="small" weight="medium">
374-
All projects
380+
All {t.project({ case: 'lower', plural: true })}
375381
</Text>
376382
) : (
377383
<PATProjectChips projects={scopeProjects} />

0 commit comments

Comments
 (0)