-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor:
AccountPreferences
forms in favor of RHF (#30183)
- Loading branch information
1 parent
2db32f0
commit fde7229
Showing
11 changed files
with
689 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { FieldValues } from 'react-hook-form'; | ||
|
||
/** | ||
* Helper function to get dirty fields from react-hook-form | ||
* @param allFields all fields object | ||
* @param dirtyFields dirty fields object | ||
* @returns all dirty fields object | ||
*/ | ||
export const getDirtyFields = <T extends FieldValues>( | ||
allFields: T, | ||
dirtyFields: Partial<Record<keyof T, boolean | boolean[]>>, | ||
): Partial<T> => { | ||
const dirtyFieldsObjValue = Object.keys(dirtyFields).reduce((acc, currentField) => { | ||
const isDirty = Array.isArray(dirtyFields[currentField]) | ||
? (dirtyFields[currentField] as boolean[]).some((value) => value === true) | ||
: dirtyFields[currentField] === true; | ||
if (isDirty) { | ||
return { | ||
...acc, | ||
[currentField]: allFields[currentField], | ||
}; | ||
} | ||
return acc; | ||
}, {} as Partial<T>); | ||
|
||
return dirtyFieldsObjValue; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 16 additions & 35 deletions
51
apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 9 additions & 18 deletions
27
apps/meteor/client/views/account/preferences/PreferencesHighlightsSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.