Skip to content

Commit

Permalink
fix(js): Com 228 fix state persistence issue for global workflow pref…
Browse files Browse the repository at this point in the history
…erences (#6509)
  • Loading branch information
BiswaViraj authored Sep 16, 2024
1 parent 3ba10e9 commit 85717ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
3 changes: 1 addition & 2 deletions packages/js/src/ui/api/hooks/usePreferences.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createEffect, createResource, createSignal, onCleanup, onMount } from 'solid-js';
import { reconcile } from 'solid-js/store';
import { Preference } from '../../../preferences/preference';
import { FetchPreferencesArgs } from '../../../preferences/types';
import { useNovu } from '../../context';
Expand All @@ -25,7 +24,7 @@ export const usePreferences = (options?: FetchPreferencesArgs) => {
return;
}

mutate(reconcile(data));
mutate(data);
};

novu.on('preferences.list.updated', listener);
Expand Down
31 changes: 20 additions & 11 deletions packages/js/src/ui/components/elements/Preferences/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export const Preferences = () => {
const allPreferences = createMemo(() => {
const globalPreference = preferences()?.find((preference) => preference.level === PreferenceLevel.GLOBAL);
const workflowPreferences = preferences()?.filter((preference) => preference.level === PreferenceLevel.TEMPLATE);
const workflowPreferencesIds = workflowPreferences?.map((preference) => preference.workflow?.id);

return { globalPreference, workflowPreferences };
return { globalPreference, workflowPreferences, workflowPreferencesIds };
});

createEffect(() => {
Expand Down Expand Up @@ -61,16 +62,24 @@ export const Preferences = () => {
channels={allPreferences().globalPreference?.channels || {}}
onChange={optimisticUpdate(allPreferences().globalPreference)}
/>
<For each={allPreferences().workflowPreferences}>
{(preference) => (
<PreferencesRow
localizationKey={preference.workflow!.identifier as StringLocalizationKey}
channels={preference.channels}
workflowId={preference.workflow?.id}
onChange={optimisticUpdate(preference)}
isCritical={preference.workflow?.critical}
/>
)}
<For each={allPreferences().workflowPreferencesIds}>
{(_, index) => {
const preference = () => allPreferences().workflowPreferences?.[index()] as Preference;

if (!preference()) {
return null;
}

return (
<PreferencesRow
localizationKey={preference().workflow!.identifier as StringLocalizationKey}
channels={preference().channels}
workflowId={preference().workflow?.id}
onChange={optimisticUpdate(preference())}
isCritical={preference().workflow?.critical}
/>
);
}}
</For>
</Show>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const Switch = (props: SwitchProps) => {
data-[disabled=true]:nt-opacity-40`
)}
data-disabled={props.disabled}
data-checked={props.checked}
/>
</label>
);
Expand Down

0 comments on commit 85717ff

Please sign in to comment.