-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit survey user extra properties from survey users list (#3630)
* edit survey user extra props from list * code cleanup * fixed user update * layout adjustments * layout adjustments --------- Co-authored-by: Stefano Ricci <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3a539ee
commit fffb37b
Showing
13 changed files
with
193 additions
and
74 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
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
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
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
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
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
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
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
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
55 changes: 55 additions & 0 deletions
55
.../App/views/Users/UsersListSurvey/SurveyUserExtraPropsEditor/SurveyUserExtraPropsEditor.js
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,55 @@ | ||
import React, { useCallback, useEffect, useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import * as User from '@core/user/user' | ||
|
||
import { PanelRight } from '@webapp/components' | ||
|
||
import { useSurveyUuid } from '@webapp/store/survey/hooks' | ||
|
||
import { UserAuthGroupExtraPropsEditor } from '../../UserEdit/UserAuthGroupExtraPropsEditor' | ||
import { useOnSave } from '../../UserEdit/store/actions/useOnSave' | ||
|
||
export const SurveyUserExtraPropsEditor = (props) => { | ||
const { onClose, onUserUpdate, userToUpdate } = props | ||
|
||
const surveyUuid = useSurveyUuid() | ||
const [userUpdated, setUserUpdated] = useState(userToUpdate) | ||
const saveUser = useOnSave({ userToUpdate: userUpdated }) | ||
|
||
useEffect(() => { | ||
const groupInCurrentSurvey = User.getAuthGroupBySurveyUuid({ surveyUuid })(userToUpdate) | ||
const groupExtraProps = groupInCurrentSurvey?.props?.extra | ||
setUserUpdated(User.assocAuthGroupExtraProps(groupExtraProps)(userToUpdate)) | ||
}, [surveyUuid, userToUpdate]) | ||
|
||
const onSurveyExtraPropsChange = useCallback( | ||
(extraPropsNew) => { | ||
setUserUpdated(User.assocAuthGroupExtraProps(extraPropsNew)(userUpdated)) | ||
}, | ||
[userUpdated] | ||
) | ||
|
||
const onSave = useCallback(async () => { | ||
await saveUser() | ||
onUserUpdate(userUpdated) | ||
}, [onUserUpdate, saveUser, userUpdated]) | ||
|
||
return ( | ||
<PanelRight | ||
className="survey-user-extra-props" | ||
header="usersView.editSurveyUserExtraPropsForUser" | ||
headerParams={{ userName: User.getName(userToUpdate) ?? User.getEmail(userToUpdate) }} | ||
onClose={onClose} | ||
width="55rem" | ||
> | ||
<UserAuthGroupExtraPropsEditor onChange={onSurveyExtraPropsChange} onSave={onSave} userToUpdate={userUpdated} /> | ||
</PanelRight> | ||
) | ||
} | ||
|
||
SurveyUserExtraPropsEditor.propTypes = { | ||
onClose: PropTypes.func.isRequired, | ||
onUserUpdate: PropTypes.func.isRequired, | ||
userToUpdate: PropTypes.object.isRequired, | ||
} |
1 change: 1 addition & 0 deletions
1
webapp/views/App/views/Users/UsersListSurvey/SurveyUserExtraPropsEditor/index.js
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 @@ | ||
export { SurveyUserExtraPropsEditor } from './SurveyUserExtraPropsEditor' |
Oops, something went wrong.