Skip to content

Commit

Permalink
Merge pull request #6007 from chamathns/notification-i18n-ai-branding
Browse files Browse the repository at this point in the history
Add error notification strings for branding AI
  • Loading branch information
chamathns authored Apr 19, 2024
2 parents 26a2344 + 46ad47e commit 41c6247
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/funny-rabbits-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wso2is/i18n": patch
"@wso2is/features": patch
---

Add improvement for branding AI
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* under the License.
*/

import { AlertInterface, AlertLevels } from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
import useBrandingPreference from "features/admin.branding.v1/hooks/use-branding-preference";
import { BrandingPreferenceInterface } from "features/admin.branding.v1/models";
import cloneDeep from "lodash-es/cloneDeep";
Expand All @@ -30,6 +32,9 @@ import React, {
useEffect,
useState
} from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { Dispatch } from "redux";
import { BrandingPreferenceUtils } from "../../admin.branding.v1/utils";
import useGetAIBrandingGenerationResult from "../api/use-get-ai-branding-generation-result";
import AIFeatureContext from "../context/ai-branding-feature-context";
Expand All @@ -48,8 +53,9 @@ const AIBrandingPreferenceProvider: FunctionComponent<AIBrandingPreferenceProvid
): ReactElement => {

const { children } = props;
const { t } = useTranslation();


const dispatch: Dispatch<any> = useDispatch();
const [ isGeneratingBranding, setGeneratingBranding ] = useState(false);
const [ mergedBrandingPreference, setMergedBrandingPreference ] = useState<BrandingPreferenceInterface>(null);
const [ operationId, setOperationId ] = useState<string>();
Expand Down Expand Up @@ -99,6 +105,20 @@ const AIBrandingPreferenceProvider: FunctionComponent<AIBrandingPreferenceProvid
*/
const handleGenerate = (data: BrandingGenerationResultAPIResponseInterface) => {


if (data.status !== "COMPLETED" || !data.data) {
dispatch(
addAlert<AlertInterface>({
description: t("branding:ai.notifications.generateError.description"),
level: AlertLevels.ERROR,
message: t("branding:ai.notifications.generateError.message")
}));
setBrandingGenerationCompleted(false);
setGeneratingBranding(false);

return;
}

const newBrandingPreference: BrandingPreferenceInterface = getMergedBrandingPreference(data.data);

setMergedBrandingPreference(newBrandingPreference);
Expand Down
18 changes: 18 additions & 0 deletions modules/i18n/src/models/namespaces/branding-ns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ export interface BrandingNS {
button: string;
};
};
notifications: {
generateError: {
description: string;
message: string;
};
regenerateError: {
description: string;
message: string;
};
resetSuccess: {
description: string;
message: string;
};
renderingError: {
description: string;
message: string;
};
};
screens: {
loading: {
heading: string;
Expand Down
18 changes: 18 additions & 0 deletions modules/i18n/src/translations/en-US/portals/branding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ export const branding: BrandingNS = {
button: "Try Branding AI"
}
},
notifications: {
generateError: {
description: "An error occurred while generating the branding.",
message: "Branding generation failed"
},
regenerateError: {
description: "An error occurred while regenerating the branding.",
message: "Branding regeneration failed"
},
resetSuccess: {
description: "Successfully reset the AI generated branding.",
message: "AI Branding reset successful"
},
renderingError: {
description: "An error occurred while rendering the website.",
message: "Website rendering failed"
}
},
screens: {
loading: {
heading: "Generating your branding",
Expand Down

0 comments on commit 41c6247

Please sign in to comment.