lavoce #2
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Modal, Input, Typography, Button, ConfigProvider, Switch, Select } from 'antd';
|
||||
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
|
||||
import { createTag, updateTag } from '../../../../api/master-tag';
|
||||
import { createTag, updateTag, getAllTag } from '../../../../api/master-tag';
|
||||
import { getAllDevice } from '../../../../api/master-device';
|
||||
|
||||
const { Text } = Typography;
|
||||
@@ -67,6 +67,42 @@ const DetailTag = (props) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validasi duplicate tag_number
|
||||
try {
|
||||
const params = new URLSearchParams({ limit: 10000 }); // Get all tags
|
||||
const response = await getAllTag(params);
|
||||
|
||||
if (response && response.data && response.data.data) {
|
||||
const existingTags = response.data.data;
|
||||
|
||||
// Check if tag_number already exists (exclude current tag when editing)
|
||||
const isDuplicate = existingTags.some((tag) => {
|
||||
const isSameNumber = parseInt(tag.tag_number) === tagNumberInt;
|
||||
const isDifferentTag = FormData.tag_id ? tag.tag_id !== FormData.tag_id : true;
|
||||
return isSameNumber && isDifferentTag;
|
||||
});
|
||||
|
||||
if (isDuplicate) {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
title: 'Peringatan',
|
||||
message: `Tag Number ${tagNumberInt} sudah digunakan. Silakan gunakan nomor yang berbeda.`,
|
||||
});
|
||||
setConfirmLoading(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking duplicate tag number:', error);
|
||||
NotifAlert({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
message: 'Gagal memvalidasi Tag Number. Silakan coba lagi.',
|
||||
});
|
||||
setConfirmLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FormData.data_type || FormData.data_type.trim() === '') {
|
||||
NotifOk({
|
||||
icon: 'warning',
|
||||
|
||||
Reference in New Issue
Block a user