Skip to content

Commit

Permalink
Merge pull request #176 from henryk86/develop
Browse files Browse the repository at this point in the history
gh-165 finalized Migration Messages to notifications
  • Loading branch information
SciLor authored Nov 12, 2024
2 parents cf74b83 + cd123a5 commit b624081
Show file tree
Hide file tree
Showing 27 changed files with 817 additions and 386 deletions.
120 changes: 74 additions & 46 deletions public/translations/de.json

Large diffs are not rendered by default.

116 changes: 72 additions & 44 deletions public/translations/en.json

Large diffs are not rendered by default.

116 changes: 72 additions & 44 deletions public/translations/es.json

Large diffs are not rendered by default.

116 changes: 72 additions & 44 deletions public/translations/fr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/TeddyCloudContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function TeddyCloudProvider({ children, linkOverlay }: TeddyCloudProvider
description,
icon: <LoadingOutlined />,
duration: 0,
placement: "topRight",
placement: "bottomRight",
});
};

Expand Down
48 changes: 39 additions & 9 deletions src/components/form/CertificatesDragAndDrop.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { useTranslation } from "react-i18next";
import { Upload, message, UploadFile } from "antd";
import { Upload, UploadFile } from "antd";
import { InboxOutlined } from "@ant-design/icons";

import { ApiUploadCertPostRequest, TeddyCloudApi } from "../../api";
import { defaultAPIConfig } from "../../config/defaultApiConfig";
import { useTeddyCloud } from "../../TeddyCloudContext";
import { NotificationTypeEnum } from "../../types/teddyCloudNotificationTypes";

const api = new TeddyCloudApi(defaultAPIConfig());

export const CertificateDragNDrop: React.FC<{ overlay?: string }> = ({ overlay }) => {
const { t } = useTranslation();
const { setFetchCloudStatus } = useTeddyCloud();
const { addNotification, setFetchCloudStatus } = useTeddyCloud();

const handleUpload = async (file: UploadFile<any>) => {
const formData = new FormData();
Expand All @@ -30,19 +31,32 @@ export const CertificateDragNDrop: React.FC<{ overlay?: string }> = ({ overlay }
try {
triggerWriteConfig();
} catch (e) {
message.error("Error while saving config to file.");
addNotification(
NotificationTypeEnum.Error,
t("settings.errorWhileSavingConfig"),
t("settings.errorWhileSavingConfigDetails") + e,
overlay ? t("tonieboxes.navigationTitle") : t("settings.navigationTitle")
);
}
message.success(
t("settings.certificates.uploadSuccessful", {
addNotification(
NotificationTypeEnum.Success,
t("settings.certificates.uploadSuccessful"),
t("settings.certificates.uploadSuccessfulDetails", {
filename: file.name,
})
}),
overlay ? t("tonieboxes.navigationTitle") : t("settings.navigationTitle")
);
setFetchCloudStatus((prev) => !prev);
} catch (err) {
message.error(
t("settings.certificates.uploadFailed", {
addNotification(
NotificationTypeEnum.Error,
t("settings.certificates.uploadFailed"),
t("settings.certificates.uploadFailedDetails", {
filename: file.name,
})
}) +
": " +
err,
overlay ? t("tonieboxes.navigationTitle") : t("settings.navigationTitle")
);
}
};
Expand All @@ -53,6 +67,22 @@ export const CertificateDragNDrop: React.FC<{ overlay?: string }> = ({ overlay }
const props = {
name: "file",
multiple: true,
beforeUpload: (file: UploadFile) => {
if (file.type !== "application/x-x509-ca-cert" && !file.name.endsWith(".der")) {
addNotification(
NotificationTypeEnum.Error,
t("settings.certificates.uploadFailed"),
t("settings.certificates.uploadFailedDetails", {
filename: file.name,
}) +
": " +
t("settings.certificates.invalidFileType"),
overlay ? t("tonieboxes.navigationTitle") : t("settings.navigationTitle")
);
return Upload.LIST_IGNORE;
}
return true;
},
customRequest: async (options: any) => {
const { onSuccess, onError, file } = options;
try {
Expand Down
53 changes: 30 additions & 23 deletions src/components/settings/SettingsSubNav.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import { MenuProps, message } from "antd";
import { MenuProps } from "antd";
import {
SafetyCertificateOutlined,
SettingOutlined,
Expand All @@ -17,51 +17,59 @@ import { defaultAPIConfig } from "../../config/defaultApiConfig";

import { StyledSubMenu } from "../StyledComponents";
import { restartServer } from "../../utils/restartServer";
import { useTeddyCloud } from "../../TeddyCloudContext";
import { NotificationTypeEnum } from "../../types/teddyCloudNotificationTypes";

const api = new TeddyCloudApi(defaultAPIConfig());

export const SettingsSubNav = () => {
const { t } = useTranslation();
const { addNotification, addLoadingNotification, closeLoadingNotification } = useTeddyCloud();
const [selectedKey, setSelectedKey] = useState("");
const [messageApi, contextHolder] = message.useMessage();
const handleRestartServer = async () => {
await restartServer(true);
setSelectedKey("");
};

const extractBaseUrl = (fullUrl: URL) => {
const url = new URL(fullUrl);
const port = url.port ? `:${url.port}` : "";
return `${url.protocol}//${url.hostname}${port}`;
};

const handleRestartServer = async () => {
await restartServer(true, addNotification, addLoadingNotification, closeLoadingNotification);
setSelectedKey("");
};

const handleReloadToniesJson = async () => {
const hideLoading = message.loading(t("settings.toniesJsonReloadInProgress"), 0);
const key = "reloadToniesJson";
addLoadingNotification(key, t("settings.toniesJsonReload"), t("settings.toniesJsonReloadInProgress"));

try {
const response = await api.apiGetTeddyCloudApiRaw("/api/toniesJsonReload");
const data = await response.text();
setSelectedKey("");

closeLoadingNotification(key);
if (data.toString() !== "OK") {
hideLoading();
messageApi.open({
type: "error",
content: t("settings.toniesJsonReloadFailed"),
});
addNotification(
NotificationTypeEnum.Error,
t("settings.toniesJsonReloadFailed"),
t("settings.toniesJsonReloadFailed") + ": " + data.toString(),
t("settings.navigationTitle")
);
} else {
hideLoading();
messageApi.open({
type: "success",
content: t("settings.toniesJsonReloadSuccessful"),
});
addNotification(
NotificationTypeEnum.Success,
t("settings.toniesJsonReloadSuccessful"),
t("settings.toniesJsonReloadSuccessful"),
t("settings.navigationTitle")
);
}
} catch (error) {
hideLoading();
messageApi.open({
type: "error",
content: t("settings.toniesJsonReloadFailed"),
});
addNotification(
NotificationTypeEnum.Error,
t("settings.toniesJsonReloadFailed"),
t("settings.toniesJsonReloadFailed") + ": " + error,
t("settings.navigationTitle")
);
}
};

Expand Down Expand Up @@ -118,7 +126,6 @@ export const SettingsSubNav = () => {

return (
<>
{contextHolder}
<StyledSubMenu mode="inline" selectedKeys={[selectedKey]} defaultOpenKeys={["sub"]} items={subnav} />
</>
);
Expand Down
8 changes: 7 additions & 1 deletion src/components/tonieboxes/boxSetup/CommonContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import tbEsp32Uart from "../../../assets/boxSetup/tb-esp32-uart.png";

import { BoxVersionsEnum, TonieboxCardProps } from "../../../types/tonieboxTypes";
import CodeSnippet from "../../utils/CodeSnippet";
import { handleTCCADerDownload } from "../../../utils/helpers";

interface TonieboxPropsWithStatusAndVersion extends TonieboxCardProps {
status: string;
Expand Down Expand Up @@ -121,11 +122,16 @@ J103 Pinout`}
);
}

export function certificateIntro(): JSX.Element {
export function certificateIntro(asC2Der: boolean): JSX.Element {
const { t } = useTranslation();
return (
<>
<Paragraph>{t("tonieboxes.boxFlashingCommon.certificatesIntro")}</Paragraph>
<Paragraph>
<Button onClick={() => handleTCCADerDownload(asC2Der)}>
{asC2Der ? t("tonieboxes.downloadC2DerFile") : t("tonieboxes.downloadCADerFile")}
</Button>
</Paragraph>
<h4>{t("tonieboxes.boxFlashingCommon.dumpCertificates")}</h4>
<Paragraph>{t("tonieboxes.boxFlashingCommon.dumpCertificatesIntro1")}</Paragraph>
<Paragraph>{t("tonieboxes.boxFlashingCommon.dumpCertificatesIntro2")}</Paragraph>
Expand Down
18 changes: 15 additions & 3 deletions src/components/tonies/ToniesCustomJsonEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Modal, Form, Input, Button, Col, Row, message, Tooltip, Alert } from "antd";
import { Modal, Form, Input, Button, Col, Row, Tooltip, Alert } from "antd";
import { InfoCircleOutlined } from "@ant-design/icons";

import { TonieCardProps } from "../../types/tonieTypes";

import { TeddyCloudApi } from "../../api";
import { defaultAPIConfig } from "../../config/defaultApiConfig";
import CodeSnippet from "../utils/CodeSnippet";
import { useTeddyCloud } from "../../TeddyCloudContext";

const api = new TeddyCloudApi(defaultAPIConfig());

Expand All @@ -31,6 +32,7 @@ export const ToniesCustomJsonEditor: React.FC<ToniesCustomJsonEditorProps> = ({
hash,
}) => {
const { t } = useTranslation();
const { addNotification } = useTeddyCloud();
const [form] = Form.useForm();

useEffect(() => {
Expand Down Expand Up @@ -101,10 +103,20 @@ export const ToniesCustomJsonEditor: React.FC<ToniesCustomJsonEditorProps> = ({
}
resetForm();
message.success(t("tonies.addNewCustomTonieModal.successfullyCreated"));
addNotification(
NotificationTypeEnum.Success,
t("tonies.addNewCustomTonieModal.successfullyCreated"),
t("tonies.addNewCustomTonieModal.successfullyCreatedDetails", { series: values.series, model: values.model }),
t("tonies.addToniesCustomJsonEntry")
);
onClose();
} catch (error) {
message.error(t("tonies.addNewCustomTonieModal.failedToCreate") + error);
addNotification(
NotificationTypeEnum.Error,
t("tonies.addNewCustomTonieModal.failedToCreate"),
t("tonies.addNewCustomTonieModal.failedToCreateDetails", { series: values.series, model: values.model }) + error,
t("tonies.addToniesCustomJsonEntry")
);
}
*/
};
Expand Down
Loading

0 comments on commit b624081

Please sign in to comment.