Skip to content

Commit 8242a66

Browse files
committed
Add translation keys in admin/api-keys
1 parent d994a81 commit 8242a66

File tree

6 files changed

+67
-56
lines changed

6 files changed

+67
-56
lines changed

src/app/admin/api-keys/ApiKeysDataTable.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { Input } from "@app/components/ui/input";
3232
import { DataTablePagination } from "@app/components/DataTablePagination";
3333
import { Plus, Search } from "lucide-react";
3434
import { DataTable } from "@app/components/ui/data-table";
35+
import { useTranslations } from "next-intl";
3536

3637
interface DataTableProps<TData, TValue> {
3738
columns: ColumnDef<TData, TValue>[];
@@ -44,15 +45,17 @@ export function ApiKeysDataTable<TData, TValue>({
4445
columns,
4546
data
4647
}: DataTableProps<TData, TValue>) {
48+
49+
const t = useTranslations();
4750
return (
4851
<DataTable
4952
columns={columns}
5053
data={data}
51-
title="API Keys"
52-
searchPlaceholder="Search API keys..."
54+
title={t('apiKeys')}
55+
searchPlaceholder={t('searchApiKeys')}
5356
searchColumn="name"
5457
onAdd={addApiKey}
55-
addButtonText="Generate API Key"
58+
addButtonText={t('apiKeysAdd')}
5659
/>
5760
);
5861
}

src/app/admin/api-keys/ApiKeysTable.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { createApiClient } from "@app/lib/api";
2424
import { useEnvContext } from "@app/hooks/useEnvContext";
2525
import moment from "moment";
2626
import { ApiKeysDataTable } from "./ApiKeysDataTable";
27+
import { useTranslations } from "next-intl";
2728

2829
export type ApiKeyRow = {
2930
id: string;
@@ -45,14 +46,16 @@ export default function ApiKeysTable({ apiKeys }: ApiKeyTableProps) {
4546

4647
const api = createApiClient(useEnvContext());
4748

49+
const t = useTranslations();
50+
4851
const deleteSite = (apiKeyId: string) => {
4952
api.delete(`/api-key/${apiKeyId}`)
5053
.catch((e) => {
51-
console.error("Error deleting API key", e);
54+
console.error(t('apiKeysErrorDelete'), e);
5255
toast({
5356
variant: "destructive",
54-
title: "Error deleting API key",
55-
description: formatAxiosError(e, "Error deleting API key")
57+
title: t('apiKeysErrorDelete'),
58+
description: formatAxiosError(e, t('apiKeysErrorDeleteMessage'))
5659
});
5760
})
5861
.then(() => {
@@ -86,15 +89,15 @@ export default function ApiKeysTable({ apiKeys }: ApiKeyTableProps) {
8689
setSelected(apiKeyROw);
8790
}}
8891
>
89-
<span>View settings</span>
92+
<span>{t('viewSettings')}</span>
9093
</DropdownMenuItem>
9194
<DropdownMenuItem
9295
onClick={() => {
9396
setSelected(apiKeyROw);
9497
setIsDeleteModalOpen(true);
9598
}}
9699
>
97-
<span className="text-red-500">Delete</span>
100+
<span className="text-red-500">{t('delete')}</span>
98101
</DropdownMenuItem>
99102
</DropdownMenuContent>
100103
</DropdownMenu>
@@ -111,7 +114,7 @@ export default function ApiKeysTable({ apiKeys }: ApiKeyTableProps) {
111114
column.toggleSorting(column.getIsSorted() === "asc")
112115
}
113116
>
114-
Name
117+
{t('name')}
115118
<ArrowUpDown className="ml-2 h-4 w-4" />
116119
</Button>
117120
);
@@ -141,7 +144,7 @@ export default function ApiKeysTable({ apiKeys }: ApiKeyTableProps) {
141144
<div className="flex items-center justify-end">
142145
<Link href={`/admin/api-keys/${r.id}`}>
143146
<Button variant={"outlinePrimary"} className="ml-2">
144-
Edit
147+
{t('edit')}
145148
<ArrowRight className="ml-2 w-4 h-4" />
146149
</Button>
147150
</Link>
@@ -163,27 +166,24 @@ export default function ApiKeysTable({ apiKeys }: ApiKeyTableProps) {
163166
dialog={
164167
<div className="space-y-4">
165168
<p>
166-
Are you sure you want to remove the API key{" "}
167-
<b>{selected?.name || selected?.id}</b>?
169+
{t('apiKeysQuestionRemove', {selectedApiKey: selected?.name || selected?.id})}
168170
</p>
169171

170172
<p>
171173
<b>
172-
Once removed, the API key will no longer be
173-
able to be used.
174+
{t('apiKeysMessageRemove')}
174175
</b>
175176
</p>
176177

177178
<p>
178-
To confirm, please type the name of the API key
179-
below.
179+
{t('apiKeysMessageConfirm')}
180180
</p>
181181
</div>
182182
}
183-
buttonText="Confirm Delete API Key"
183+
buttonText={t('apiKeysDeleteConfirm')}
184184
onConfirm={async () => deleteSite(selected!.id)}
185185
string={selected.name}
186-
title="Delete API Key"
186+
title={t('apiKeysDelete')}
187187
/>
188188
)}
189189

src/app/admin/api-keys/[apiKeyId]/layout.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { GetApiKeyResponse } from "@server/routers/apiKeys";
2121
import ApiKeyProvider from "@app/providers/ApiKeyProvider";
2222
import { HorizontalTabs } from "@app/components/HorizontalTabs";
23+
import { useTranslations } from "next-intl";
2324

2425
interface SettingsLayoutProps {
2526
children: React.ReactNode;
@@ -29,6 +30,8 @@ interface SettingsLayoutProps {
2930
export default async function SettingsLayout(props: SettingsLayoutProps) {
3031
const params = await props.params;
3132

33+
const t = useTranslations();
34+
3235
const { children } = props;
3336

3437
let apiKey = null;
@@ -45,14 +48,14 @@ export default async function SettingsLayout(props: SettingsLayoutProps) {
4548

4649
const navItems = [
4750
{
48-
title: "Permissions",
51+
title: t('apiKeysPermissionsTitle'),
4952
href: "/admin/api-keys/{apiKeyId}/permissions"
5053
}
5154
];
5255

5356
return (
5457
<>
55-
<SettingsSectionTitle title={`${apiKey?.name} Settings`} />
58+
<SettingsSectionTitle title={t('apiKeysSettings', {apiKeyName: apiKey?.name})} />
5659

5760
<ApiKeyProvider apiKey={apiKey}>
5861
<HorizontalTabs items={navItems}>{children}</HorizontalTabs>

src/app/admin/api-keys/[apiKeyId]/permissions/page.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ import { ListApiKeyActionsResponse } from "@server/routers/apiKeys";
2323
import { AxiosResponse } from "axios";
2424
import { useParams } from "next/navigation";
2525
import { useEffect, useState } from "react";
26+
import { useTranslations } from "next-intl";
2627

2728
export default function Page() {
2829
const { env } = useEnvContext();
2930
const api = createApiClient({ env });
3031
const { apiKeyId } = useParams();
3132

33+
const t = useTranslations();
34+
3235
const [loadingPage, setLoadingPage] = useState<boolean>(true);
3336
const [selectedPermissions, setSelectedPermissions] = useState<
3437
Record<string, boolean>
@@ -47,10 +50,10 @@ export default function Page() {
4750
.catch((e) => {
4851
toast({
4952
variant: "destructive",
50-
title: "Error loading API key actions",
53+
title: t('apiKeysPermissionsErrorLoadingActions'),
5154
description: formatAxiosError(
5255
e,
53-
"Error loading API key actions"
56+
t('apiKeysPermissionsErrorLoadingActions')
5457
)
5558
});
5659
});
@@ -81,18 +84,18 @@ export default function Page() {
8184
)
8285
})
8386
.catch((e) => {
84-
console.error("Error setting permissions", e);
87+
console.error(t('apiKeysPermissionsErrorUpdate'), e);
8588
toast({
8689
variant: "destructive",
87-
title: "Error setting permissions",
90+
title: t('apiKeysPermissionsErrorUpdate'),
8891
description: formatAxiosError(e)
8992
});
9093
});
9194

9295
if (actionsRes && actionsRes.status === 200) {
9396
toast({
94-
title: "Permissions updated",
95-
description: "The permissions have been updated."
97+
title: t('apiKeysPermissionsUpdated'),
98+
description: t('apiKeysPermissionsUpdatedDescription')
9699
});
97100
}
98101

@@ -106,10 +109,10 @@ export default function Page() {
106109
<SettingsSection>
107110
<SettingsSectionHeader>
108111
<SettingsSectionTitle>
109-
Permissions
112+
{t('apiKeysPermissionsTitle')}
110113
</SettingsSectionTitle>
111114
<SettingsSectionDescription>
112-
Determine what this API key can do
115+
{t('apiKeysPermissionsGeneralSettingsDescription')}
113116
</SettingsSectionDescription>
114117
</SettingsSectionHeader>
115118
<SettingsSectionBody>
@@ -127,7 +130,7 @@ export default function Page() {
127130
loading={loadingSavePermissions}
128131
disabled={loadingSavePermissions}
129132
>
130-
Save Permissions
133+
{t('apiKeysPermissionsSave')}
131134
</Button>
132135
</SettingsSectionFooter>
133136
</SettingsSectionBody>

0 commit comments

Comments
 (0)