add settings permissions update (#11377)
Fixes https://github.com/twentyhq/core-team-issues/issues/710
This commit is contained in:
26
packages/twenty-front/src/utils/getDirtyFields.ts
Normal file
26
packages/twenty-front/src/utils/getDirtyFields.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { isDeeplyEqual } from './isDeeplyEqual';
|
||||
|
||||
export const getDirtyFields = <T extends Record<string, any>>(
|
||||
draft: T,
|
||||
persisted: T | null | undefined,
|
||||
): Partial<T> => {
|
||||
if (!persisted) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(draft).filter(([, value]) => value !== undefined),
|
||||
) as Partial<T>;
|
||||
}
|
||||
|
||||
const dirty: Partial<T> = {};
|
||||
const allKeys = new Set([...Object.keys(draft), ...Object.keys(persisted)]);
|
||||
|
||||
for (const key of allKeys) {
|
||||
const draftValue = draft[key as keyof T];
|
||||
const persistedValue = persisted[key as keyof T];
|
||||
|
||||
if (!isDeeplyEqual(draftValue, persistedValue)) {
|
||||
dirty[key as keyof T] = draftValue;
|
||||
}
|
||||
}
|
||||
|
||||
return dirty;
|
||||
};
|
||||
Reference in New Issue
Block a user