Skip to content

Commit 00b670a

Browse files
committed
[PRAC/cont] Add checks to handle incoming data
Organiz checks for incom/uncorrect data to createModalWindowByType() f.. Worth noting: - that these checks improve the stability and predictability this function. core: B-3 / JS-BL
1 parent afd501e commit 00b670a

File tree

1 file changed

+17
-0
lines changed
  • core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js

1 file changed

+17
-0
lines changed

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,23 @@
912912
let modalContactsArr = []; // глобальная инициализация массива контактов (будущих row-контактов)
913913

914914
function createModalWindowByType(type, clientData = {}) {
915+
// проверка входящего аргумента/параметра "type" (отработка по default)
916+
const validTypes = ['add', 'edit'];
917+
if (!validTypes.includes(type)) {
918+
console.error(`Invalid type: "${type}". Defaulting to "add"!`);
919+
type = 'add';
920+
}
921+
922+
// при типе "edit" проверка наличия/корректности свойства id
923+
if (
924+
type === 'edit' &&
925+
(!clientData.id || typeof clientData.id !== 'string')
926+
) {
927+
console.warn(
928+
'Missing or invalid "id" in clientData! Some features may not work as expected!'
929+
);
930+
}
931+
915932
const modalId = type === 'add' ? 'add-modal' : 'edit-modal';
916933
const modalTitle = type === 'add' ? 'Новый клиент' : 'Изменить данные';
917934
const modalCancelBtn = type === 'add' ? 'Отмена' : 'Удалить клиента';

0 commit comments

Comments
 (0)