Fixed creation of users + better frontend handling of permissions
This commit is contained in:
@@ -8,3 +8,33 @@ export function cn(...inputs: ClassValue[]) {
|
||||
export function toTitleCase(str: string) {
|
||||
return str.replace(/\b\w/g, (char) => char.toUpperCase());
|
||||
}
|
||||
|
||||
namespace DiffUtils {
|
||||
export function getDifferences<T extends object>(
|
||||
obj1: T,
|
||||
obj2: T,
|
||||
): Partial<T> {
|
||||
return Object.entries(obj2).reduce((diff, [key, value]) => {
|
||||
if (
|
||||
JSON.stringify(obj1[key as keyof T]) !==
|
||||
JSON.stringify(obj2[key as keyof T])
|
||||
) {
|
||||
diff[key as keyof T] = value as T[keyof T];
|
||||
}
|
||||
return diff;
|
||||
}, {} as Partial<T>);
|
||||
}
|
||||
|
||||
export function isEmpty<T extends object>(obj: T) {
|
||||
return Object.keys(obj).length === 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Make it globally available
|
||||
if (typeof window !== "undefined") {
|
||||
(window as any).DiffUtils = DiffUtils;
|
||||
} else {
|
||||
(global as any).DiffUtils = DiffUtils;
|
||||
}
|
||||
|
||||
export default DiffUtils;
|
||||
|
||||
Reference in New Issue
Block a user