{"size": 1550, "ext": "js", "max_stars_repo_path": "src/settings/CustomFieldsSettings.js", "max_stars_repo_name": "usavkov-epam/ui-users", "max_stars_repo_stars_event_min_datetime": "2018-02-06T19:45:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-13T06:18:15.000Z", "max_issues_repo_path": "src/settings/CustomFieldsSettings.js", "max_issues_repo_name": "usavkov-epam/ui-users", "max_issues_repo_issues_event_min_datetime": "2017-01-06T00:04:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:47:42.000Z", "max_forks_repo_path": "src/settings/CustomFieldsSettings.js", "max_forks_repo_name": "usavkov-epam/ui-users", "max_forks_repo_forks_event_min_datetime": "2017-01-05T22:53:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T13:37:28.000Z"}
{"max_stars_count": 4, "max_issues_count": 1339, "max_forks_count": 61, "avg_line_length": 25.8333333333, "max_line_length": 101, "alphanum_fraction": 0.6638709677}
import React from 'react';
import PropTypes from 'prop-types';
import { Switch, Route } from 'react-router-dom';

import { useStripes } from '@folio/stripes/core';
import { ViewCustomFieldsSettings, EditCustomFieldsSettings } from '@folio/stripes/smart-components';

const propTypes = {
  history: PropTypes.shape({
    push: PropTypes.func.isRequired,
    replace: PropTypes.func.isRequired,
  }).isRequired,
};

const CustomFieldsSettings = ({
  history,
}) => {
  const stripes = useStripes();

  const base = '/settings/users/custom-fields';

  const permissions = {
    canView: stripes.hasPerm('ui-users.settings.customfields.view'),
    canEdit: stripes.hasPerm('ui-users.settings.customfields.edit'),
    canDelete: stripes.hasPerm('ui-users.settings.customfields.all'),
  };

  const backendModuleName = 'users';
  const entityType = 'user';

  if (!permissions.canView) {
    history.replace('/settings/users');
  }

  return (
    <Switch>
      <Route exact path={base}>
        <ViewCustomFieldsSettings
          backendModuleName={backendModuleName}
          entityType={entityType}
          editRoute={`${base}/edit`}
          permissions={permissions}
        />
      </Route>
      <Route exact path={`${base}/edit`}>
        <EditCustomFieldsSettings
          backendModuleName={backendModuleName}
          entityType={entityType}
          viewRoute={base}
          permissions={permissions}
        />
      </Route>
    </Switch>
  );
};

CustomFieldsSettings.propTypes = propTypes;

export default CustomFieldsSettings;
