Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hook for fetching branding preference #5996

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-lamps-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/features": patch
---

Use hooks to fetch branding preference instead of using the context provider
16 changes: 11 additions & 5 deletions features/admin.ai.v1/providers/ai-branding-preference-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* under the License.
*/

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";
import isEmpty from "lodash-es/isEmpty";
Expand All @@ -30,6 +29,9 @@ import React, {
useEffect,
useState
} from "react";
import { useSelector } from "react-redux";
import useGetBrandingPreferenceResolve from "../../admin.branding.v1/api/use-get-branding-preference-resolve";
import { AppState } from "../../admin.core.v1/store";
import useGetAIBrandingGenerationResult from "../api/use-get-ai-branding-generation-result";
import AIFeatureContext from "../context/ai-branding-feature-context";
import { BrandingGenerationResultAPIResponseInterface } from "../models/branding-preferences";
Expand All @@ -48,13 +50,17 @@ const AIBrandingPreferenceProvider: FunctionComponent<AIBrandingPreferenceProvid

const { children } = props;

const { preference } = useBrandingPreference();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we update the PR description with the reason for opting out of retrieving branding preferences from the context?

Also, if we are not using the branding preferences from context anywhere, let's remove it from the context too.


const [ isGeneratingBranding, setGeneratingBranding ] = useState(false);
const [ mergedBrandingPreference, setMergedBrandingPreference ] = useState<BrandingPreferenceInterface>(null);
const [ operationId, setOperationId ] = useState<string>();
const [ brandingGenerationCompleted, setBrandingGenerationCompleted ] = useState(false);

const tenantDomain: string = useSelector((state: AppState) => state.auth.tenantDomain);

const {
data: brandingPreference
} = useGetBrandingPreferenceResolve(tenantDomain);
Comment on lines +60 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we handle loading, error states?


/**
* Removes empty keys from an object.
*
Expand Down Expand Up @@ -113,9 +119,9 @@ const AIBrandingPreferenceProvider: FunctionComponent<AIBrandingPreferenceProvid
const { theme } = removeEmptyKeys(data);
const { activeTheme, LIGHT, DARK } = theme;

const mergedBrandingPreference: BrandingPreferenceInterface = merge(cloneDeep(preference.preference), {
const mergedBrandingPreference: BrandingPreferenceInterface = merge(cloneDeep(brandingPreference.preference), {
theme: {
...preference.preference.theme,
...brandingPreference.preference.theme,
DARK: DARK,
LIGHT: LIGHT,
activeTheme: activeTheme
Expand Down
Loading