Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pham Tuan committed Jun 15, 2023
1 parent c35a9d8 commit 8989203
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/components/admin/layout.admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const LayoutAdmin = () => {

useEffect(() => {
setActiveMenu(location.pathname)
console.log(">>> location. pathname", location.pathname)
}, [location])

const handleLogout = async () => {
Expand Down
50 changes: 28 additions & 22 deletions src/components/admin/role/modal.role.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ const ModalRole = (props: IProps) => {
const result = _(res.data?.result)
.groupBy(x => x.module)
.map((value, key) => {
value = value.map(item => {
item.isSelected = false;
return item;
});
return { module: key, permissions: value };
})
.value();
Expand All @@ -48,28 +44,38 @@ const ModalRole = (props: IProps) => {
}, [])

const submitRole = async (valuesForm: any) => {
const { name, description, isActive, permissions } = valuesForm;
if (dataInit?._id) {
//update
const role = {
name, description, isActive, permissions
}
const { description, isActive, name, permissions } = valuesForm;
const checkedPermissions = [];

const res = await callUpdateRole(role, dataInit._id);
if (res.data) {
message.success("Cập nhật role thành công");
handleReset();
reloadTable();
} else {
notification.error({
message: 'Có lỗi xảy ra',
description: res.message
});
if (permissions) {
for (const key in permissions) {
if (key.match(/^[0-9a-fA-F]{24}$/) && permissions[key] === true) {
checkedPermissions.push(key);
}
}
}

if (dataInit?._id) {
// //update
// const role = {
// name, description, isActive, permissions
// }

// const res = await callUpdateRole(role, dataInit._id);
// if (res.data) {
// message.success("Cập nhật role thành công");
// handleReset();
// reloadTable();
// } else {
// notification.error({
// message: 'Có lỗi xảy ra',
// description: res.message
// });
// }
} else {
//create
const role = {
name, description, isActive, permissions
name, description, isActive, permissions: checkedPermissions
}
const res = await callCreateRole(role);
if (res.data) {
Expand Down Expand Up @@ -167,7 +173,7 @@ const ModalRole = (props: IProps) => {
>
<ModuleApi
// onChange={onChangeModuleApi}
initData={(dataInit?.permissions)}
initData={(dataInit?.permissions) as IPermission[]}
form={form}
listPermissions={listPermissions}
/>
Expand Down
21 changes: 11 additions & 10 deletions src/components/admin/role/module.api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface IProps {

const ModuleApi = (props: IProps) => {
const { form, listPermissions } = props;
const [collapseOpen, setCollapseOpen] = useState<any[] | any>([])

useEffect(() => {
if (listPermissions && listPermissions?.length) {
Expand All @@ -41,21 +42,21 @@ const ModuleApi = (props: IProps) => {
if (child) {
child?.permissions?.forEach(item => {
if (item._id)
form.setFieldValue(item._id, value)
form.setFieldValue(["permissions", item._id], value)
})
}
}

const handleSingleCheck = (value: boolean, child: string, parent: string) => {
form.setFieldValue(child, value);
form.setFieldValue(["permissions", child], value);

//check all
const temp = listPermissions?.find(item => item.module === parent);
if (temp) {
const restPermission = temp?.permissions?.filter(item => item._id !== child);
if (restPermission && restPermission.length) {
const allTrue = restPermission.every(item => form.getFieldValue((item._id) as string));
form.setFieldValue(parent, allTrue && value)
form.setFieldValue(["permissions", parent], allTrue && value)
}
}
}
Expand All @@ -64,23 +65,23 @@ const ModuleApi = (props: IProps) => {
return (
<Card size="small" bordered={false}>
<Collapse
onChange={setCollapseOpen}
>
{
listPermissions?.map((item, index) => (
<Panel
header={<div>{item.module}</div>}
key={index}
collapsible='header'

extra={
<div className={'customize-form-item'}>
<div className={'customize-form-item'} hidden={!_.includes(collapseOpen, index + "")}>
<ProFormSwitch
name={item.module}
name={["permissions", item.module]}
fieldProps={{
defaultChecked: false,
onChange: (v) => handleSwitchAll(v, item.module)
onClick: (u, e) => { e.stopPropagation() },
onChange: (v) => handleSwitchAll(v, item.module),
}}

/>
</div>
}
Expand All @@ -92,7 +93,7 @@ const ModuleApi = (props: IProps) => {
<Card size="small" bodyStyle={{ display: "flex", flex: 1, flexDirection: 'row' }}>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<ProFormSwitch
name={value._id}
name={["permissions", value._id as string]}
fieldProps={{
defaultChecked: false,
onChange: (v) => handleSingleCheck(v, (value._id) as string, item.module)
Expand All @@ -103,7 +104,7 @@ const ModuleApi = (props: IProps) => {
<Tooltip title={value?.name}>
<p style={{ paddingLeft: 10, marginBottom: 3 }}>{value?.name || ''}</p>
<div style={{ display: 'flex' }}>
<p style={{ paddingLeft: 10, fontWeight: 'bold', marginBottom: 0, color: colorMethod(value?.method) }}>{value?.method || ''}</p>
<p style={{ paddingLeft: 10, fontWeight: 'bold', marginBottom: 0, color: colorMethod(value?.method as string) }}>{value?.method || ''}</p>
<p style={{ paddingLeft: 10, marginBottom: 0, color: grey[5] }}>{value?.apiPath || ''}</p>
</div>
</Tooltip>
Expand Down
1 change: 0 additions & 1 deletion src/components/client/header.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const Header = (props: any) => {


const onClick: MenuProps['onClick'] = (e) => {
console.log('click ', e);
setCurrent(e.key);
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/client/modal/apply.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const ApplyModal = (props: IProps) => {
},
onChange(info) {
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList);
// console.log(info.file, info.fileList);
}
if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`);
Expand Down
11 changes: 5 additions & 6 deletions src/types/backend.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ export interface IResume {

export interface IPermission {
_id?: string;
name: string;
apiPath: string;
method: string;
module: string;
isSelected?: boolean;
name?: string;
apiPath?: string;
method?: string;
module?: string;

createdBy?: string;
isDeleted?: boolean;
Expand All @@ -135,7 +134,7 @@ export interface IRole {
name: string;
description: string;
isActive: boolean;
permissions: IPermission[];
permissions: IPermission[] | string[];

createdBy?: string;
isDeleted?: boolean;
Expand Down

0 comments on commit 8989203

Please sign in to comment.