-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blokh/fix/refactor update category #517
Merged
+164
−89
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
82ef4f8
added watch for form
Blokh b3056f9
feat: finalized update form of category type
Blokh c4bf161
removed log
Blokh d7e9b90
feat(added usewatchdropdown logic for category to type logic): added …
Blokh 97b972c
updated compose to edit naming
Blokh d5f5aec
Merge branch 'dev' into blokh/fix/refactor-update-category
Blokh b1fc2bb
feat(merged with dev): merged with dev
Blokh 1d84d73
updated use initial category set
Blokh de08545
added types to uniqueArrayByKey
Blokh e6dd4c3
fixed entries to document
Blokh 90665a5
minor refactoring
Blokh 0cdb497
updated common version
Blokh cc8246d
Merge branch 'dev' into blokh/fix/refactor-update-category
Blokh b90804f
added find value
Blokh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(added usewatchdropdown logic for category to type logic): added …
…usewatchdropdown added usewatchdropdown logic for category to type logic
- Loading branch information
commit d7e9b9038f138956357bbb4e3eb7846299e5b927
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
33 changes: 33 additions & 0 deletions
33
apps/backoffice-v2/src/pages/Entity/components/EditableDetails/hooks/useWatchDropdown.ts
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,33 @@ | ||
import { useEffect } from 'react'; | ||
import { TDropdownOption } from '../types'; | ||
export const useWatchDropdownOptions = ({ form, data, setFormData }) => { | ||
const watch = form.watch; | ||
|
||
useEffect(() => { | ||
const subscription = watch((value, { name }) => { | ||
if (!['category'].includes(name)) return subscription.unsubscribe(); | ||
const newData = structuredClone(data); | ||
|
||
newData | ||
.filter(item => !!item.dropdownOptions) | ||
.filter(item => | ||
item.dropdownOptions.find(dropdownOption => dropdownOption.dependantOn === name), | ||
) | ||
.forEach(item => { | ||
item.dropdownOptions = item.dropdownOptions.filter( | ||
(dropdownOption: TDropdownOption) => dropdownOption.dependantValue === value[name], | ||
); | ||
item.value = item.dropdownOptions.find( | ||
dropDownOption => dropDownOption.value == value, | ||
)?.value; | ||
|
||
form.setValue(item.title, `${item.value}`); | ||
return (newData[newData.indexOf(item)] = item); | ||
}); | ||
|
||
setFormData(newData); | ||
}); | ||
|
||
return () => subscription.unsubscribe(); | ||
}, [watch, data, setFormData]); | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of space is necessary here :) Prettier & ESLint should do it, will fix it sometime.