Skip to content

Commit 2fa0629

Browse files
committed
improved external auth provider mode (store it in the local storage for persistence); send selected locale with requests
1 parent d8d60b7 commit 2fa0629

16 files changed

+153
-127
lines changed

src/components/etke.cc/BillingPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const BillingPage = () => {
6161

6262
try {
6363
setLoading(true);
64-
const response = await dataProvider.getPayments(etkeccAdmin);
64+
const response = await dataProvider.getPayments(etkeccAdmin, locale);
6565
setPaymentsData(response.payments);
6666
setMaintenance(response.maintenance);
6767
} catch (error) {
@@ -73,14 +73,14 @@ const BillingPage = () => {
7373
};
7474

7575
fetchBillingData();
76-
}, [etkeccAdmin, dataProvider, notify]);
76+
}, [etkeccAdmin, dataProvider, notify, locale]);
7777

7878
const handleInvoiceDownload = async (transactionId: string) => {
7979
if (!etkeccAdmin || downloadingInvoice) return;
8080

8181
try {
8282
setDownloadingInvoice(transactionId);
83-
await dataProvider.getInvoice(etkeccAdmin, transactionId);
83+
await dataProvider.getInvoice(etkeccAdmin, locale, transactionId);
8484
notify("etkecc.billing.helper.download_started", { type: "info" });
8585
} catch (error) {
8686
// Use the specific error message from the dataProvider

src/components/etke.cc/InstanceConfig.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ let instanceConfig: InstanceConfig = {
2525
disabled: {},
2626
};
2727

28-
export const FetchInstanceConfig = async (etkeccAdminUrl: string | undefined) => {
28+
export const FetchInstanceConfig = async (etkeccAdminUrl: string | undefined, locale = "") => {
2929
if (!etkeccAdminUrl || etkeccAdminUrl === "") {
3030
return;
3131
}
3232

3333
try {
34-
const resp = await fetch(`${etkeccAdminUrl}/config`);
34+
const resp = await fetch(`${etkeccAdminUrl}/config`, {
35+
headers: {
36+
"Accept-Language": locale,
37+
},
38+
});
3539
if (resp.status === 200) {
3640
const configJSON = (await resp.json()) as InstanceConfig;
3741
instanceConfig = configJSON;
@@ -43,7 +47,7 @@ export const FetchInstanceConfig = async (etkeccAdminUrl: string | undefined) =>
4347
case 204:
4448
return;
4549
case 429:
46-
setTimeout(() => FetchInstanceConfig(etkeccAdminUrl), 1000);
50+
setTimeout(() => FetchInstanceConfig(etkeccAdminUrl, locale), 1000);
4751
return;
4852
}
4953
console.error(`Error fetching instance config: ${resp.status} ${resp.statusText}`);

src/components/etke.cc/ServerCommandsPanel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
Typography,
1515
} from "@mui/material";
1616
import { useEffect, useState } from "react";
17-
import { Button, Loading, useDataProvider, useCreatePath, useStore, useTranslate } from "react-admin";
17+
import { Button, Loading, useDataProvider, useCreatePath, useLocale, useStore, useTranslate } from "react-admin";
1818
import { Link as RouterLink } from "react-router-dom";
1919

2020
import { EtkeAttribution } from "./EtkeAttribution";
@@ -48,6 +48,7 @@ const ServerCommandsPanel = () => {
4848
const [commandIsRunning, setCommandIsRunning] = useState<boolean>(serverProcess.command !== "");
4949
const [commandResult, setCommandResult] = useState<React.ReactNode[]>([]);
5050
const dataProvider = useDataProvider();
51+
const locale = useLocale();
5152

5253
useEffect(() => {
5354
if (serverProcess.command === "") {
@@ -132,7 +133,7 @@ const ServerCommandsPanel = () => {
132133

133134
const updateServerProcessStatus = async (command: ServerCommand) => {
134135
const commandIsLocking = command.with_lock;
135-
const serverProcess = await dataProvider.getServerRunningProcess(etkeccAdmin, true);
136+
const serverProcess = await dataProvider.getServerRunningProcess(etkeccAdmin, locale, true);
136137
if (!commandIsLocking && serverProcess.command === "") {
137138
// if command is not locking, we simulate the "lock" mechanism so notifications will be refetched
138139
serverProcess["command"] = command.name;

src/components/etke.cc/ServerNotificationsBadge.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
Tooltip,
1919
} from "@mui/material";
2020
import { Fragment, useEffect, useState } from "react";
21-
import { useDataProvider, useStore, useTranslate } from "react-admin";
21+
import { useDataProvider, useLocale, useStore, useTranslate } from "react-admin";
2222
import { useNavigate } from "react-router";
2323

2424
import { useAppContext } from "../../Context";
@@ -42,11 +42,13 @@ const useServerNotifications = () => {
4242

4343
const { etkeccAdmin } = useAppContext();
4444
const dataProvider = useDataProvider();
45+
const locale = useLocale();
4546
const { notifications, success } = serverNotifications;
4647

4748
const fetchNotifications = async () => {
4849
const notificationsResponse: ServerNotificationsResponse = await dataProvider.getServerNotifications(
4950
etkeccAdmin,
51+
locale,
5052
command !== ""
5153
);
5254
const serverNotifications = [...notificationsResponse.notifications];
@@ -59,7 +61,7 @@ const useServerNotifications = () => {
5961
};
6062

6163
const deleteServerNotifications = async () => {
62-
const deleteResponse = await dataProvider.deleteServerNotifications(etkeccAdmin);
64+
const deleteResponse = await dataProvider.deleteServerNotifications(etkeccAdmin, locale);
6365
if (deleteResponse.success) {
6466
setServerNotifications({
6567
notifications: [],
@@ -88,7 +90,7 @@ const useServerNotifications = () => {
8890
clearInterval(serverNotificationsInterval);
8991
}
9092
};
91-
}, [etkeccAdmin, command, locked_at]);
93+
}, [etkeccAdmin, locale, command, locked_at]);
9294

9395
return { success, notifications, deleteServerNotifications };
9496
};

src/components/etke.cc/ServerNotificationsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ServerNotificationsPage = () => {
3333
variant="text"
3434
color="error"
3535
onClick={async () => {
36-
await dataProvider.deleteServerNotifications(etkeccAdmin);
36+
await dataProvider.deleteServerNotifications(etkeccAdmin, locale);
3737
setServerNotifications({
3838
notifications: [],
3939
success: true,

src/components/etke.cc/ServerStatusBadge.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BadgeProps } from "@mui/material/Badge";
44
import { styled } from "@mui/material/styles";
55
import { useTheme } from "@mui/material/styles";
66
import { useEffect } from "react";
7-
import { Button, useDataProvider, useStore, useTranslate } from "react-admin";
7+
import { Button, useDataProvider, useLocale, useStore, useTranslate } from "react-admin";
88
import { useNavigate } from "react-router";
99

1010
import { useAppContext } from "../../Context";
@@ -68,12 +68,13 @@ const useServerStatus = () => {
6868
const { command } = serverProcess;
6969
const { etkeccAdmin } = useAppContext();
7070
const dataProvider = useDataProvider();
71+
const locale = useLocale();
7172
const isOkay = serverStatus.ok;
7273
const successCheck = serverStatus.success;
7374
const maintenance = serverStatus.maintenance;
7475

7576
const checkServerStatus = async () => {
76-
const serverStatus: ServerStatusResponse = await dataProvider.getServerStatus(etkeccAdmin, command !== "");
77+
const serverStatus: ServerStatusResponse = await dataProvider.getServerStatus(etkeccAdmin, locale, command !== "");
7778
setServerStatus({
7879
ok: serverStatus.ok,
7980
maintenance: serverStatus.maintenance,
@@ -105,7 +106,7 @@ const useServerStatus = () => {
105106
clearInterval(serverStatusInterval);
106107
}
107108
};
108-
}, [etkeccAdmin, command]);
109+
}, [etkeccAdmin, locale, command]);
109110

110111
return { isOkay, successCheck, maintenance };
111112
};
@@ -118,11 +119,13 @@ const useCurrentServerProcess = () => {
118119
});
119120
const { etkeccAdmin } = useAppContext();
120121
const dataProvider = useDataProvider();
122+
const locale = useLocale();
121123
const { command, locked_at, maintenance } = serverProcess;
122124

123125
const checkServerRunningProcess = async () => {
124126
const serverProcess: ServerProcessResponse = await dataProvider.getServerRunningProcess(
125127
etkeccAdmin,
128+
locale,
126129
command !== ""
127130
);
128131
setServerProcess({
@@ -154,7 +157,7 @@ const useCurrentServerProcess = () => {
154157
clearInterval(serverCheckInterval);
155158
}
156159
};
157-
}, [etkeccAdmin, command]);
160+
}, [etkeccAdmin, locale, command]);
158161

159162
return { command, locked_at, maintenance };
160163
};

src/components/etke.cc/hooks/useServerCommands.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect } from "react";
2-
import { useDataProvider } from "react-admin";
2+
import { useDataProvider, useLocale } from "react-admin";
33

44
import { useAppContext } from "../../../Context";
55
import { ServerCommand } from "../../../synapse/dataProvider";
@@ -8,14 +8,15 @@ import { GetInstanceConfig } from "../InstanceConfig";
88
export const useServerCommands = () => {
99
const icfg = GetInstanceConfig();
1010
const { etkeccAdmin } = useAppContext();
11+
const locale = useLocale();
1112
const [isLoading, setLoading] = useState(true);
1213
const [maintenance, setMaintenance] = useState(false);
1314
const [serverCommands, setServerCommands] = useState<Record<string, ServerCommand>>({});
1415
const dataProvider = useDataProvider();
1516

1617
useEffect(() => {
1718
const fetchServerCommands = async () => {
18-
const serverCommandsResponse = await dataProvider.getServerCommands(etkeccAdmin);
19+
const serverCommandsResponse = await dataProvider.getServerCommands(etkeccAdmin, locale);
1920
if (serverCommandsResponse?.maintenance) {
2021
setMaintenance(true);
2122
setLoading(false);
@@ -37,7 +38,7 @@ export const useServerCommands = () => {
3738
setLoading(false);
3839
};
3940
fetchServerCommands();
40-
}, [dataProvider, etkeccAdmin]);
41+
}, [dataProvider, etkeccAdmin, locale]);
4142

4243
return { isLoading, maintenance, serverCommands, setServerCommands };
4344
};

src/components/etke.cc/schedules/components/recurring/RecurringCommandEdit.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
SaveButton,
99
useNotify,
1010
useDataProvider,
11+
useLocale,
1112
Loading,
1213
Button,
1314
SelectInput,
@@ -51,6 +52,7 @@ const RecurringCommandEdit = () => {
5152
const notify = useNotify();
5253
const dataProvider = useDataProvider();
5354
const queryClient = useQueryClient();
55+
const locale = useLocale();
5456
const translate = useTranslate();
5557
const { etkeccAdmin } = useAppContext();
5658
const [command, setCommand] = useState<RecurringCommand | undefined>(undefined);
@@ -122,10 +124,10 @@ const RecurringCommandEdit = () => {
122124
}
123125

124126
if (isCreating) {
125-
await dataProvider.createRecurringCommand(etkeccAdmin, submissionData);
127+
await dataProvider.createRecurringCommand(etkeccAdmin, locale, submissionData);
126128
notify("etkecc.actions.recurring.action.create_success", { type: "success" });
127129
} else {
128-
await dataProvider.updateRecurringCommand(etkeccAdmin, {
130+
await dataProvider.updateRecurringCommand(etkeccAdmin, locale, {
129131
...submissionData,
130132
id: id,
131133
});

src/components/etke.cc/schedules/components/recurring/RecurringDeleteButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import DeleteIcon from "@mui/icons-material/Delete";
22
import { useTheme } from "@mui/material/styles";
33
import { useState } from "react";
4-
import { useNotify, useDataProvider, useRecordContext, useTranslate } from "react-admin";
4+
import { useLocale, useNotify, useDataProvider, useRecordContext, useTranslate } from "react-admin";
55
import { Button, Confirm } from "react-admin";
66
import { useNavigate } from "react-router-dom";
77

@@ -12,6 +12,7 @@ const RecurringDeleteButton = () => {
1212
const record = useRecordContext() as RecurringCommand;
1313
const { etkeccAdmin } = useAppContext();
1414
const dataProvider = useDataProvider();
15+
const locale = useLocale();
1516
const notify = useNotify();
1617
const translate = useTranslate();
1718
const theme = useTheme();
@@ -27,7 +28,7 @@ const RecurringDeleteButton = () => {
2728
const handleConfirm = async () => {
2829
setIsDeleting(true);
2930
try {
30-
await dataProvider.deleteRecurringCommand(etkeccAdmin, record.id);
31+
await dataProvider.deleteRecurringCommand(etkeccAdmin, locale, record.id);
3132
notify("etkecc.actions.recurring.action.delete_success", { type: "success" });
3233
navigate("/server_actions");
3334
} catch (error) {

src/components/etke.cc/schedules/components/scheduled/ScheduledCommandEdit.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SaveButton,
1010
useNotify,
1111
useDataProvider,
12+
useLocale,
1213
Loading,
1314
Button,
1415
SelectInput,
@@ -50,6 +51,7 @@ const ScheduledCommandEdit = () => {
5051
const navigate = useNavigate();
5152
const notify = useNotify();
5253
const dataProvider = useDataProvider();
54+
const locale = useLocale();
5355
const translate = useTranslate();
5456
const { etkeccAdmin } = useAppContext();
5557
const [command, setCommand] = useState<ScheduledCommand | null>(null);
@@ -78,10 +80,10 @@ const ScheduledCommandEdit = () => {
7880
try {
7981
data.scheduled_at = new Date(data.scheduled_at).toISOString();
8082
if (isCreating) {
81-
await dataProvider.createScheduledCommand(etkeccAdmin, data);
83+
await dataProvider.createScheduledCommand(etkeccAdmin, locale, data);
8284
notify("etkecc.actions.scheduled.action.create_success", { type: "success" });
8385
} else {
84-
await dataProvider.updateScheduledCommand(etkeccAdmin, {
86+
await dataProvider.updateScheduledCommand(etkeccAdmin, locale, {
8587
...data,
8688
id: id,
8789
});

0 commit comments

Comments
 (0)