Skip to content
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

[WIP] New User Fields #993

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions packages/admin/src/pages/users/Form/AboutForm.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import PropTypes from 'prop-types';
import React from 'react';
import {
AutocompleteInput,
AutocompleteArrayInput,
CheckboxGroupInput,
AutocompleteInput,
BooleanInput,
DateTimeInput,
FormDataConsumer,
ReferenceInput,
required,
SelectInput,
SimpleForm,
TextField,
TextInput,
useQuery,
FormDataConsumer,
} from 'react-admin';
import { ReferenceArrayInput, statuses, CityInput } from '../../../components';
import { CityInput, statuses } from '../../../components';

const AboutForm = ({ record, save, resource }) => {
record.role = record?.role_id;
Expand Down Expand Up @@ -119,10 +119,7 @@ const AboutForm = ({ record, save, resource }) => {
<ReferenceInput source="role" reference="roles" validate={[required()]} fullWidth>
<SelectInput optionText="role" />
</ReferenceInput>

<ReferenceArrayInput source="permissions" reference="permissions">
<CheckboxGroupInput optionText="description" />
</ReferenceArrayInput>
<BooleanInput label="Incluir no banco de pesquisadores" source="researcher" />
</SimpleForm>
);
};
Expand Down
32 changes: 32 additions & 0 deletions packages/admin/src/pages/users/Form/Permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import PropTypes from 'prop-types';
import React from 'react';
import { CheckboxGroupInput, SimpleForm } from 'react-admin';
import { ReferenceArrayInput } from '../../../components';

const Permissions = ({ record, save, resource }) => {
const permissions = record?.permissions.map((permission) => permission.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <react/prop-types> reported by reviewdog 🐶
'record.permissions' is missing in props validation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <react/prop-types> reported by reviewdog 🐶
'record.permissions.map' is missing in props validation

const newRecord = {
permissions,
};
return (
<SimpleForm record={newRecord} save={save} resource={resource}>
<ReferenceArrayInput source="permissions" reference="permissions">
<CheckboxGroupInput optionText="description" row={false} />
</ReferenceArrayInput>
</SimpleForm>
);
};

Permissions.propTypes = {
record: PropTypes.shape({}),
resource: PropTypes.string,
save: PropTypes.func,
};

Permissions.defaultProps = {
record: {},
resource: '',
save: () => {},
};

export default Permissions;
12 changes: 8 additions & 4 deletions packages/admin/src/pages/users/Form/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import { TabbedShowLayout, Tab, Error, Loading, useQuery } from 'react-admin';
import Technologies from './Technologies';
import Reviews from './Reviews';
import React from 'react';
import { Error, Loading, Tab, TabbedShowLayout, useQuery } from 'react-admin';
import AboutForm from './AboutForm';
import Bookmarks from './Bookmarks';
import Institution from './Institution';
import Permissions from './Permissions';
import Reviews from './Reviews';
import Technologies from './Technologies';
import Uploads from './Uploads';

const UsersForm = ({ record, resource, save, basePath }) => {
Expand Down Expand Up @@ -43,6 +44,9 @@ const UsersForm = ({ record, resource, save, basePath }) => {
<Tab label="labels.uploads" path="uploads">
<Uploads />
</Tab>
<Tab label="labels.permissions" path="permissions">
<Permissions save={save} />
</Tab>
</TabbedShowLayout>
);
};
Expand Down