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

Fix bugs #1

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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
8 changes: 8 additions & 0 deletions bbbeasy-backend/app/src/Actions/Roles/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public function save($f3, $params): void

return;
}

if ($role->id == 1 || $role->id == 2) {
$this->logger->error('Role could not be updated', ['error' => 'Role could not be updated']);
$this->renderJson(['errors' => ['id' => 'Role could not be updated']], ResponseCode::HTTP_PRECONDITION_FAILED);

return;
}

} else {
$this->logger->error($errorMessage, ['errors' => $dataChecker->getErrors()]);
$this->renderJson(['errors' => $dataChecker->getErrors()], ResponseCode::HTTP_UNPROCESSABLE_ENTITY);
Expand Down
146 changes: 146 additions & 0 deletions bbbeasy-frontend/src/components/EditableTableUsers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
* BBBEasy open source platform - https://riadvice.tn/
*
* Copyright (c) 2022-2023 RIADVICE SUARL and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Affero General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BBBeasy is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along
* with BBBEasy; if not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import { Trans } from 'react-i18next';
import EN_US from '../locale/en-US.json';
import { t } from 'i18next';

import { Form, Space } from 'antd';

import { RecordingType } from '../types/RecordingType';
import { UserType } from '../types/UserType';
import { RoleType } from '../types/RoleType';
import { LabelType } from '../types/LabelType';

type Props = {
editing: boolean;
children: React.ReactNode;
dataIndex: string;
record: RecordingType | LabelType | UserType | RoleType;
inputNode: JSX.Element;
errorsEdit: object;
editRules?: object;

editable?: boolean;
editComponent?: React.ReactNode;
mouseOverFct?: () => void;
mouseLeaveFct?: () => void;

showLabelColor?: boolean;
inputColor?: JSX.Element;
};

const EditableTableUsers: React.FC<Props> = ({
editing,
children,
dataIndex,
record,
inputNode,
errorsEdit,
editRules,
editable,
editComponent,
mouseOverFct,
mouseLeaveFct,
showLabelColor,
inputColor,
...restProps
}) => {
let firstTest = false;
let secondTest = false;

if (editable != undefined) {
if (editing) {
firstTest = true;
} else {
secondTest = true;
}
} else {
if (editing) {
firstTest = true;
}
}

const customFormItem = (index: string, customInputNode: JSX.Element) => {
if (index != 'description') {
return (
<Form.Item
name={index}
className="input-editable"
{...(index in errorsEdit &&
record.key == errorsEdit['key'] && {
help: (
<Trans
i18nKey={Object.keys(EN_US).filter((elem) => EN_US[elem] == errorsEdit[index])}
/>
),
validateStatus: 'error',
})}
rules={[
{
required: true,
message: t('required_' + index),
},
{ ...editRules },
]}
>
{customInputNode}
</Form.Item>
);
} else {
return (
<Form.Item
name={index}
className="input-editable"
{...(index in errorsEdit &&
record.key == errorsEdit['key'] && {
help: (
<Trans
i18nKey={Object.keys(EN_US).filter((elem) => EN_US[elem] == errorsEdit[index])}
/>
),
validateStatus: 'error',
})}
>
{customInputNode}
</Form.Item>
);
}
};

return (
<td {...restProps} onMouseOver={mouseOverFct} onMouseLeave={mouseLeaveFct}>
{firstTest ? (
<Space size="middle">
{customFormItem(dataIndex, inputNode)}
{showLabelColor && customFormItem('color', inputColor)}
</Space>
) : secondTest ? (
<>
{children}
{editComponent}
</>
) : (
children
)}
</td>
);
};

export default EditableTableUsers;
41 changes: 23 additions & 18 deletions bbbeasy-frontend/src/components/Presets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ type formType = {
};

const PresetsCol: React.FC<PresetColProps> = ({
key,
preset,
editName,
editClickHandler,
copyClickHandler,
deleteClickHandler,
key,
preset,
editName,
editClickHandler,
copyClickHandler,
deleteClickHandler,
}) => {
const [file, setFile] = React.useState<UploadFile>(null);
const [fileList, setFileList] = React.useState<UploadFile[]>(null);
Expand Down Expand Up @@ -208,13 +208,21 @@ const PresetsCol: React.FC<PresetColProps> = ({
setErrorsEdit({});
setIsEditing(false);
};
function compareObjs(obj1,obj2){
return JSON.stringify(obj1)===JSON.stringify(obj2);
}
const handleSaveEdit = async () => {
setErrorsEdit({});
try {
const values = (await editForm.validateFields()) as formType;

PresetsService.edit_preset(values, preset.id)
.then((response) => {
if (compareObjs(response.data.preset, preset)) {
Notifications.openNotificationWithIcon('info', t('no_changes'));
cancelEdit();
return;
}
editClickHandler(response.data.preset, preset);

cancelEdit();
Expand Down Expand Up @@ -395,8 +403,8 @@ const PresetsCol: React.FC<PresetColProps> = ({
? 'leftTop'
: 'left'
: item.enabled
? 'rightTop'
: 'right'
? 'rightTop'
: 'right'
}
overlayClassName={item.enabled ? 'install-tooltip' : 'title-tooltip'}
title={
Expand Down Expand Up @@ -472,11 +480,11 @@ const PresetsCol: React.FC<PresetColProps> = ({
value={
item.value == true
? ReactDomServer.renderToString(
<Trans i18nKey="status_presets_active" />
)
<Trans i18nKey="status_presets_active" />
)
: ReactDomServer.renderToString(
<Trans i18nKey="status_presets_inactive" />
)
<Trans i18nKey="status_presets_inactive" />
)
}
/>

Expand Down Expand Up @@ -573,8 +581,8 @@ const PresetsCol: React.FC<PresetColProps> = ({
label:
'Guest Policy' == modalTitle
? ReactDomServer.renderToString(
<Trans i18nKey={data.key} />
)
<Trans i18nKey={data.key} />
)
: data.name,
value: data.value,
}))}
Expand Down Expand Up @@ -651,10 +659,7 @@ const Presets = () => {

//edit
const editPreset = (newPreset: MyPresetType, oldPreset: MyPresetType) => {
if (newPreset.name == oldPreset.name) {
Notifications.openNotificationWithIcon('info', t('no_changes'));
return;
}

const newPresets = [...myPresets];
const index = newPresets.findIndex((item) => oldPreset.id === item.id);
if (index > -1 && newPreset != undefined) {
Expand Down
14 changes: 11 additions & 3 deletions bbbeasy-frontend/src/components/Roles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import EN_US from '../locale/en-US.json';

import { PageHeader } from '@ant-design/pro-layout';

import { Button, Row, Col, Typography, Space, Modal, Popconfirm, Card, Checkbox, Input } from 'antd';
import {Button, Row, Col, Typography, Space, Modal, Popconfirm, Card, Checkbox, Input, Alert} from 'antd';
import {
DeleteOutlined,
QuestionCircleOutlined,
Expand Down Expand Up @@ -408,12 +408,20 @@ const Roles = () => {
editable={editable}
editComponent={
isShown &&
AuthService.isAllowedAction(actions, 'edit') && (
AuthService.isAllowedAction(actions, 'edit') &&(
<Button
size="small"
type="link"
icon={<EditOutlined className="cell-edit-icon" />}
onClick={toggleEditName}
onClick={()=>{

if(record.key == 1 || record.key == 2 ){
Notifications.openNotificationWithIcon('info', t('role_name'));
return;
}
toggleEditName()

}}
/>
)
}
Expand Down
14 changes: 12 additions & 2 deletions bbbeasy-frontend/src/components/RoomDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ const RoomDetails = () => {
if (currentUser != null) {
PresetsService.list_presets(currentUser.id).then((result) => {
setPresets(result.data);
});
})
.catch((error) => {
console.log(error);
navigate('/');
})

}
};
const getLabels = () => {
Expand All @@ -166,7 +171,11 @@ const RoomDetails = () => {
labels_data.push({ label: label.name, value: label.color });
});
setLabels(labels_data);
});
})
.catch((error) => {
console.log(error);
navigate('/');
});
};
const getRoomRecordings = (id) => {
setLoading(true);
Expand All @@ -177,6 +186,7 @@ const RoomDetails = () => {
})
.catch((error) => {
console.log(error);
navigate('/');
})
.finally(() => {
setLoading(false);
Expand Down
20 changes: 10 additions & 10 deletions bbbeasy-frontend/src/components/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { DeleteOutlined, EditOutlined, QuestionCircleOutlined, StarFilled } from
import { FormInstance } from 'antd/lib/form';
import { CompareRecords } from '../functions/compare.function';
import { EditableTable } from './EditableTable';
import EditableTableCell from './EditableTableCell';
import EditableTableUsers from './EditableTableUsers';
import Notifications from './Notifications';
import AddUserForm from './AddUserForm';
import EditableTableColumnSearch from './EditableTableColumnSearch';
Expand Down Expand Up @@ -203,13 +203,13 @@ const Users = () => {
// edit
const [editForm] = Form.useForm();
const EditableCell: React.FC<EditableCellProps> = ({
editing,
children,
dataIndex,
record,
inputType,
...restProps
}) => {
editing,
children,
dataIndex,
record,
inputType,
...restProps
}) => {
let inputNode: JSX.Element;
if (inputType === 'select') {
const statesOptions = allStates.map((item, index) => (
Expand All @@ -223,7 +223,7 @@ const Users = () => {
inputNode = <Input onFocus={() => setCancelVisibility(false)} />;
}
return (
<EditableTableCell
<EditableTableUsers
editing={editing}
dataIndex={dataIndex}
record={record}
Expand All @@ -245,7 +245,7 @@ const Users = () => {
{...restProps}
>
{children}
</EditableTableCell>
</EditableTableUsers>
);
};
const isEditing = (record: UserType) => record.key == editingKey;
Expand Down
2 changes: 1 addition & 1 deletion bbbeasy-frontend/src/components/layout/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const AppHeader = () => {
setCurrentUser(null);
localStorage.removeItem('session');
setCurrentSession(null);
navigate('/login');
navigate('/');
})
.catch((error) => {
console.log(error);
Expand Down
3 changes: 2 additions & 1 deletion bbbeasy-frontend/src/locale/ar-TN.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,6 @@

"email-not-exist": "المستخدم غير موجود مع هذا البريد الإلكتروني",
"publish_record_success": "تم نشر التسجيل بنجاح",
"unpublish_record_success": "تم إلغاء نشر التسجيل بنجاح"
"unpublish_record_success": "تم إلغاء نشر التسجيل بنجاح",
"role_name": "لا يمكن تغيير هذا الاسم"
}
3 changes: 2 additions & 1 deletion bbbeasy-frontend/src/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,6 @@

"email-not-exist": "User does not exist with this email",
"publish_record_success": "Recording published successfully",
"unpublish_record_success": "Recording unpublished successfully"
"unpublish_record_success": "Recording unpublished successfully",
"role_name": "This name cannot be changed"
}
Loading