Skip to content

Commit

Permalink
[TM-1385] change position of create user button to user list in admin…
Browse files Browse the repository at this point in the history
… view (#709)
  • Loading branch information
cesarLima1 authored Nov 27, 2024
1 parent df28d4a commit 2df8bc5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
22 changes: 22 additions & 0 deletions src/admin/components/Actions/ListActionsCreateFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import DownloadIcon from "@mui/icons-material/GetApp";
import { Button, CreateButton, FilterButton, TopToolbar } from "react-admin";
import { When } from "react-if";

interface ListActionsCreateFilterProps {
isSuperAdmin?: boolean;
onExport?: () => void;
}

const ListActionsCreateFilter = ({ isSuperAdmin, onExport }: ListActionsCreateFilterProps) => (
<TopToolbar>
<When condition={isSuperAdmin}>
<CreateButton className="filter-button-page-admin" />
</When>
<FilterButton className="filter-button-page-admin" />
<When condition={!!onExport}>
<Button className="button-page-admin" label="Export" startIcon={<DownloadIcon />} onClick={onExport} />
</When>
</TopToolbar>
);

export default ListActionsCreateFilter;
6 changes: 4 additions & 2 deletions src/admin/modules/user/components/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
} from "react-admin";

import { UserDataProvider } from "@/admin/apiProvider/dataProviders/userDataProvider";
import ListActions from "@/admin/components/Actions/ListActions";
import ListActionsCreateFilter from "@/admin/components/Actions/ListActionsCreateFilter";
import ExportProcessingAlert from "@/admin/components/Alerts/ExportProcessingAlert";
import { useGetUserRole } from "@/admin/hooks/useGetUserRole";
import Menu from "@/components/elements/Menu/Menu";
import { MENU_PLACEMENT_BOTTOM_LEFT } from "@/components/elements/Menu/MenuVariant";
import Text from "@/components/elements/Text/Text";
Expand Down Expand Up @@ -90,6 +91,7 @@ const UserDataGrid = () => {

export const UserList = () => {
const [exporting, setExporting] = useState<boolean>(false);
const { isSuperAdmin } = useGetUserRole();

const userDataProvider = useDataProvider<UserDataProvider>();

Expand All @@ -106,7 +108,7 @@ export const UserList = () => {
</Text>
</Stack>

<List actions={<ListActions onExport={handleExport} />} filters={filters}>
<List actions={<ListActionsCreateFilter isSuperAdmin={isSuperAdmin} onExport={handleExport} />} filters={filters}>
<UserDataGrid />
</List>

Expand Down
24 changes: 1 addition & 23 deletions src/admin/modules/user/components/UserShowAside.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import { Box, Button, Divider, Grid, Stack, Typography } from "@mui/material";
import { useState } from "react";
import {
BooleanField,
RaRecord,
SelectField,
TextField,
useNotify,
useRedirect,
useRefresh,
useShowContext
} from "react-admin";
import { When } from "react-if";
import { BooleanField, RaRecord, SelectField, TextField, useNotify, useRefresh, useShowContext } from "react-admin";

import Aside from "@/admin/components/Aside/Aside";
import { ConfirmationDialog } from "@/admin/components/Dialogs/ConfirmationDialog";
import { useGetUserRole } from "@/admin/hooks/useGetUserRole";
import { ResetPasswordDialog } from "@/admin/modules/user/components/ResetPasswordDialog";
import {
usePatchV2AdminUsersVerifyUUID,
Expand All @@ -29,8 +18,6 @@ import { userPrimaryRoleChoices } from "../const";
export const UserShowAside = () => {
const notify = useNotify();
const refresh = useRefresh();
const redirect = useRedirect();
const { isSuperAdmin } = useGetUserRole();

const [showResetPasswordDialog, setShowResetPasswordDialog] = useState(false);
const [showVerifyEmailDialog, setShowVerifyEmailDialog] = useState(false);
Expand Down Expand Up @@ -66,10 +53,6 @@ export const UserShowAside = () => {
}
});

const handleCreateUser = () => {
redirect("create", "user");
};

return (
<>
<Aside title="User Review">
Expand All @@ -94,11 +77,6 @@ export const UserShowAside = () => {
<Divider />
<Box pt={2}>
<Stack direction="row" alignItems="center" gap={2} flexWrap="wrap">
<When condition={isSuperAdmin}>
<Button variant="contained" onClick={handleCreateUser}>
Create User
</Button>
</When>
<Button
variant="contained"
onClick={() =>
Expand Down

0 comments on commit 2df8bc5

Please sign in to comment.