Skip to content

Commit

Permalink
Merge pull request #2359 from clari182/fix/editors-dropdown-roles
Browse files Browse the repository at this point in the history
Fetch editors and admin to enable edit on submissions
  • Loading branch information
kepae authored Oct 17, 2023
2 parents 576ab64 + 00e332a commit 03d41df
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const SubmissionEdit = ({ id }) => {
const [createEntityMutation] = useMutation(UPSERT_ENTITY);

const { data: userData, loading: userLoading } = useQuery(FIND_USERS_BY_ROLE, {
variables: { role: 'editor' },
variables: { role: ['editor', 'admin'] },
});

const addToast = useToastContext();
Expand Down
40 changes: 21 additions & 19 deletions site/gatsby-site/src/components/submissions/SubmissionEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,25 +391,27 @@ const SubmissionEditForm = ({ handleSubmit, saving, setSaving, userLoading, user
<div className="editors-dropdown">
{!userLoading && (
<Dropdown label={t('Editors')} color={'light'}>
{userData.users.map((user) => {
const isChecked =
selectedOptions.findIndex((editor) => editor.userId === user.userId) > -1;

return (
<DropdownItem key={`editors-${user.userId}`}>
<div className="flex justify-center items-center gap-2">
<Checkbox
id={`checkbox-${user.userId}`}
checked={isChecked}
onClick={(ev) => handleSelect(ev.target.checked, user.userId)}
/>
<Label htmlFor={`checkbox-${user.userId}`}>
{user.first_name} {user.last_name}
</Label>
</div>
</DropdownItem>
);
})}
{userData.users
.filter((user) => user.first_name || user.last_name)
.map((user) => {
const isChecked =
selectedOptions.findIndex((editor) => editor.userId === user.userId) > -1;

return (
<DropdownItem key={`editors-${user.userId}`}>
<div className="flex justify-center items-center gap-2">
<Checkbox
id={`checkbox-${user.userId}`}
checked={isChecked}
onClick={(ev) => handleSelect(ev.target.checked, user.userId)}
/>
<Label htmlFor={`checkbox-${user.userId}`}>
{user.first_name} {user.last_name}
</Label>
</div>
</DropdownItem>
);
})}
</Dropdown>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/src/graphql/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export const FIND_USER = gql`
`;

export const FIND_USERS_BY_ROLE = gql`
query FindUsersByRole($role: String!) {
users(query: { roles_in: [$role] }) {
query FindUsersByRole($role: [String!]) {
users(query: { roles_in: $role }) {
roles
userId
first_name
Expand Down

0 comments on commit 03d41df

Please sign in to comment.