@iotready/nextjs-components-library 1.0.0-preview37 → 1.0.0-preview38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ declare const GroupUpdate: ({ isOrg, labelEntity, groupInfo, usersGroup, usersLi
9
9
  handleUpdateDevice: (id: string, body: any, user: UserType) => Promise<any>;
10
10
  handleGetGroups: (userInfo?: UserType, parent_id?: string) => Promise<any>;
11
11
  handleUpdateGroup: (id: string, group: any) => Promise<void>;
12
- handleDeleteGroup: (id: string) => Promise<void>;
12
+ handleDeleteGroup: (id: string, isOrg: boolean) => Promise<void>;
13
13
  container?: "Box" | "Card";
14
14
  containerProps?: any;
15
15
  afterUpdateCallback?: (groupInfo: any) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Box, Typography, Card, CardContent, TableBody } from '@mui/material';
4
4
  import Grid from '@mui/material/Grid2';
5
5
  import { useEffect, useState } from 'react';
@@ -10,7 +10,7 @@ import DeleteIcon from '@mui/icons-material/Delete';
10
10
  import { LoadingButton } from '@mui/lab';
11
11
  const GroupUpdate = ({ isOrg, labelEntity, groupInfo, usersGroup, usersList, devicesList, userInfo, handleAddUserToGroup, handleGetGroups, handleRemoveUserFromGroup, handleUpdateGroup, handleDeleteGroup, container = 'Box', containerProps = {}, afterUpdateCallback, afterRemoveCallback, confirmMui }) => {
12
12
  const [group, setGroup] = useState(groupInfo);
13
- const [organizationsGroup, setOrganizationsGroup] = useState([]);
13
+ const [organizationsGroup, setOrganizationsGroup] = useState(null);
14
14
  const [loadingUpdateButton, setLoadingUpdateButton] = useState(false);
15
15
  const [loadingRemoveUserButton, setLoadingRemoveUserButton] = useState(false);
16
16
  const [loadingAddUserButton, setLoadingAddUserButton] = useState(false);
@@ -81,7 +81,7 @@ const GroupUpdate = ({ isOrg, labelEntity, groupInfo, usersGroup, usersList, dev
81
81
  confirm("Are you sure you want to delete the group?");
82
82
  }
83
83
  setLoadingDeleteGroupButton(true);
84
- await handleDeleteGroup(group.id);
84
+ await handleDeleteGroup(group.id, isOrg);
85
85
  if (afterRemoveCallback) {
86
86
  afterRemoveCallback();
87
87
  }
@@ -99,6 +99,9 @@ const GroupUpdate = ({ isOrg, labelEntity, groupInfo, usersGroup, usersList, dev
99
99
  const response = await handleGetGroups(userInfo, group.id);
100
100
  setOrganizationsGroup(response);
101
101
  }
102
+ else {
103
+ setOrganizationsGroup([]);
104
+ }
102
105
  };
103
106
  getInitialData();
104
107
  }, []);
@@ -107,7 +110,7 @@ const GroupUpdate = ({ isOrg, labelEntity, groupInfo, usersGroup, usersList, dev
107
110
  _jsx(Table, { size: "small", children: _jsx(TableBody, { children: usersGroup.map((ug) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsx(Typography, { variant: "body1", children: ug.user.fullName }) }), _jsx(TableCell, { align: 'right', children: _jsx(LoadingButton, { size: "small", color: "error", loading: loadingRemoveUserButton, onClick: () => removeUserFromCurrentGroup(ug.user.userId), children: _jsx(CloseIcon, { sx: { m: 0, p: 0 }, fontSize: "small" }) }) })] }, ug.id))) }) })
108
111
  : _jsx(Box, { component: 'div', sx: { mt: 2 }, children: "No members found" }) }), _jsxs(Box, { component: "div", sx: { mt: 4, display: 'flex', alignItems: 'center' }, children: [_jsx(Autocomplete, { fullWidth: true, disablePortal: true, options: usersList || [], value: selectedUser, size: 'small', onChange: (event, newValue) => {
109
112
  setSelectedUser(newValue);
110
- }, renderInput: (params) => _jsx(TextField, { ...params, label: "Select user" }) }), _jsxs(LoadingButton, { variant: "contained", color: "primary", loading: loadingAddUserButton, sx: { ml: 2 }, disabled: !selectedUser, onClick: () => addUserToCurrentGroup(), children: [_jsx(AddIcon, { sx: { mr: 1 } }), " Add"] })] }), _jsxs(Box, { component: "div", sx: { mt: 4 }, children: [_jsxs(Typography, { variant: 'body1', sx: { fontWeight: 'bold' }, children: ["Delete ", labelEntity.toLocaleLowerCase()] }), _jsx(Alert, { severity: "error", sx: { mt: 2 }, action: _jsxs(LoadingButton, { variant: "contained", disabled: devicesList.length > 0 || usersGroup.length > 0, color: "error", loading: loadingDeleteGroupButton, onClick: () => deleteGroup(), size: 'small', children: [_jsx(DeleteIcon, { fontSize: "small", sx: { mr: 1 } }), " Delete"] }), children: !isOrg ? (_jsx(_Fragment, { children: devicesList.length === 0 && usersGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices and members from ${labelEntity.toLocaleLowerCase()} before deletion` })) : (_jsx(_Fragment, { children: devicesList.length === 0 && usersGroup.length === 0 && organizationsGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices and members and groups from ${labelEntity.toLocaleLowerCase()} before deletion` })) })] })] }) })] }));
113
+ }, renderInput: (params) => _jsx(TextField, { ...params, label: "Select user" }) }), _jsxs(LoadingButton, { variant: "contained", color: "primary", loading: loadingAddUserButton, sx: { ml: 2 }, disabled: !selectedUser, onClick: () => addUserToCurrentGroup(), children: [_jsx(AddIcon, { sx: { mr: 1 } }), " Add"] })] }), _jsxs(Box, { component: "div", sx: { mt: 4 }, children: [_jsxs(Typography, { variant: 'body1', sx: { fontWeight: 'bold' }, children: ["Delete ", labelEntity.toLocaleLowerCase()] }), !isOrg ? (_jsx(Alert, { severity: "error", sx: { mt: 2 }, action: _jsxs(LoadingButton, { variant: "contained", disabled: devicesList.length > 0 || usersGroup.length > 0, color: "error", loading: loadingDeleteGroupButton, onClick: () => deleteGroup(), size: 'small', children: [_jsx(DeleteIcon, { fontSize: "small", sx: { mr: 1 } }), " Delete"] }), children: devicesList.length === 0 && usersGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices and members from ${labelEntity.toLocaleLowerCase()} before deletion` })) : organizationsGroup && (_jsx(Alert, { severity: "error", sx: { mt: 2 }, action: _jsxs(LoadingButton, { variant: "contained", disabled: devicesList.length > 0 || usersGroup.length > 0 || organizationsGroup.length > 0, color: "error", loading: loadingDeleteGroupButton, onClick: () => deleteGroup(), size: 'small', children: [_jsx(DeleteIcon, { fontSize: "small", sx: { mr: 1 } }), " Delete"] }), children: devicesList.length === 0 && usersGroup.length === 0 && organizationsGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices, members and groups from ${labelEntity.toLocaleLowerCase()} before deletion` }))] })] }) })] }));
111
114
  };
112
115
  return (container === "Card" ? (_jsx(Card, { ...containerProps, children: _jsx(CardContent, { children: renderGroupUpdate() }) })) : (_jsx(Box, { ...containerProps, children: renderGroupUpdate() })));
113
116
  };
@@ -12,7 +12,7 @@ declare const GroupsDevices: ({ userInfo, handleGetUsersList, handleAddUserToGro
12
12
  handleGetPositions?: (devices: any) => Promise<DevicePositionType[]>;
13
13
  handleAddDevicesToGroup: (user: UserType, group: string, devicesToPatch: AssetType[] | TrackleDeviceType[]) => Promise<TrackleDeviceType[]>;
14
14
  handleRemoveDevicesFromGroup: (user: UserType, group: string, devicesToPatch: AssetType[] | TrackleDeviceType[]) => Promise<TrackleDeviceType[]>;
15
- handleDeleteGroup: (id: string) => Promise<void>;
15
+ handleDeleteGroup: (id: string, iOrg: boolean) => Promise<void>;
16
16
  handleUpdateGroup: (id: string, group: any) => Promise<void>;
17
17
  handleUpdateDevice: (id: string, body: any, user: UserType) => Promise<void>;
18
18
  group: string;
@@ -344,8 +344,10 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
344
344
  transform: 'translate(-50%, -50%)',
345
345
  width: 400,
346
346
  borderRadius: 4
347
- }, children: [_jsx(CardHeader, { title: "New " + labelEntity, action: _jsx(IconButton, { onClick: handleCloseAdd, children: _jsx(CloseIcon, {}) }) }), _jsx(CardContent, { children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TextField, { fullWidth: true, label: labelEntity + " Name", value: groupName, onChange: (e) => setGroupName(e.target.value), required: true }), _jsx(TextField, { fullWidth: true, label: "Description", value: description, onChange: (e) => setDescription(e.target.value), margin: "normal", multiline: true, rows: 4 }), _jsxs(Box, { mt: 2, display: "flex", justifyContent: "space-between", children: [_jsx(Button, { variant: "contained", color: "info", onClick: handleCloseAdd, children: "Cancel" }), _jsx(LoadingButton, { loading: loadingAdd, variant: "contained", color: "primary", type: "submit", children: "Create" })] })] }) })] }) }), !groupUpdateVisible && renderDatagridAndMaps, groupInfo && editGroup && groupUpdateVisible && _jsx(GroupUpdate, { userInfo: userInfo, confirmMui: confirmMui, usersGroup: usersGroup, usersList: usersList, handleGetGroups: handleGetGroups, handleUpdateDevice: handleUpdateDevice, handleAddUserToGroup: handleAddUserToGroup, handleRemoveUserFromGroup: handleRemoveUserFromGroup, groupInfo: groupInfo, afterUpdateCallback: async (groupInfo) => { setGroupInfo(groupInfo); await getGroups(); await getUsersGroup(groupInfo.id); }, afterRemoveCallback: async () => { closeEditGroup(); await getGroups(); if (!isOrg) {
347
+ }, children: [_jsx(CardHeader, { title: "New " + labelEntity, action: _jsx(IconButton, { onClick: handleCloseAdd, children: _jsx(CloseIcon, {}) }) }), _jsx(CardContent, { children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TextField, { fullWidth: true, label: labelEntity + " Name", value: groupName, onChange: (e) => setGroupName(e.target.value), required: true }), _jsx(TextField, { fullWidth: true, label: "Description", value: description, onChange: (e) => setDescription(e.target.value), margin: "normal", multiline: true, rows: 4 }), _jsxs(Box, { mt: 2, display: "flex", justifyContent: "space-between", children: [_jsx(Button, { variant: "contained", color: "info", onClick: handleCloseAdd, children: "Cancel" }), _jsx(LoadingButton, { loading: loadingAdd, variant: "contained", color: "primary", type: "submit", children: "Create" })] })] }) })] }) }), !groupUpdateVisible && renderDatagridAndMaps, groupInfo && editGroup && groupUpdateVisible && _jsx(GroupUpdate, { userInfo: userInfo, confirmMui: confirmMui, usersGroup: usersGroup, usersList: usersList, handleGetGroups: handleGetGroups, handleUpdateDevice: handleUpdateDevice, handleAddUserToGroup: handleAddUserToGroup, handleRemoveUserFromGroup: handleRemoveUserFromGroup, groupInfo: groupInfo, afterUpdateCallback: async (groupInfo) => { setGroupInfo(groupInfo); await getGroups(); await getUsersGroup(groupInfo.id); }, afterRemoveCallback: async () => { if (!isOrg) {
348
+ closeEditGroup();
348
349
  setCurrentGroup('all');
350
+ await getGroups();
349
351
  } }, container: 'Card', handleDeleteGroup: handleDeleteGroup, handleUpdateGroup: handleUpdateGroup, devicesList: devices, labelEntity: labelEntity, isOrg: isOrg })] }) }));
350
352
  };
351
353
  export default GroupsDevices;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iotready/nextjs-components-library",
3
- "version": "1.0.0-preview37",
3
+ "version": "1.0.0-preview38",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",