Skip to content

Commit

Permalink
use hook for fetching branding preference
Browse files Browse the repository at this point in the history
  • Loading branch information
chamathns committed Apr 18, 2024
1 parent fb79e5b commit 42e526d
Showing 1 changed file with 11 additions and 5 deletions.
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();

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);

/**
* 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

0 comments on commit 42e526d

Please sign in to comment.