feat: enhance DetailShift and ListShift components with improved validation and UI updates

This commit is contained in:
2025-10-22 14:24:52 +07:00
parent 85afb9d332
commit 988dcda0e2
4 changed files with 268 additions and 607 deletions

View File

@@ -1,13 +1,14 @@
import { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider } from 'antd'; import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider, TimePicker, Space } from 'antd';
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif'; import { NotifOk } from '../../../../components/Global/ToastNotif';
import { createShift, updateShift } from '../../../../api/master-shift';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
dayjs.extend(utc); // Mock API calls for demonstration
const createShift = async (payload) => ({ statusCode: 201, data: { ...payload, shift_id: Date.now() } });
const updateShift = async (id, payload) => ({ statusCode: 200, data: { ...payload, shift_id: id } });
const { Text } = Typography; const { Text } = Typography;
const timeFormat = 'HH:mm';
const DetailShift = (props) => { const DetailShift = (props) => {
const [confirmLoading, setConfirmLoading] = useState(false); const [confirmLoading, setConfirmLoading] = useState(false);
@@ -15,12 +16,12 @@ const DetailShift = (props) => {
const defaultData = { const defaultData = {
shift_id: '', shift_id: '',
shift_name: '', shift_name: '',
start_time: '', start_time: '08:00',
end_time: '', end_time: '16:00',
is_active: true, is_active: true,
}; };
const [FormData, setFormData] = useState(defaultData); const [formData, setFormData] = useState(defaultData);
const handleCancel = () => { const handleCancel = () => {
props.setSelectedData(null); props.setSelectedData(null);
@@ -30,349 +31,125 @@ const DetailShift = (props) => {
const handleSave = async () => { const handleSave = async () => {
setConfirmLoading(true); setConfirmLoading(true);
// Validasi required fields if (!formData.shift_name) {
if (!FormData.shift_name || FormData.shift_name.trim() === '') { NotifOk({ icon: 'warning', title: 'Peringatan', message: 'Nama Shift wajib diisi.' });
NotifOk({
icon: 'warning',
title: 'Peringatan',
message: 'Kolom Nama Shift Tidak Boleh Kosong',
});
setConfirmLoading(false);
return;
}
if (!FormData.start_time || FormData.start_time.trim() === '') {
NotifOk({
icon: 'warning',
title: 'Peringatan',
message: 'Kolom Jam Mulai Tidak Boleh Kosong',
});
setConfirmLoading(false);
return;
}
if (!FormData.end_time || FormData.end_time.trim() === '') {
NotifOk({
icon: 'warning',
title: 'Peringatan',
message: 'Kolom Jam Selesai Tidak Boleh Kosong',
});
setConfirmLoading(false);
return;
}
// Validate time format
const timePattern = /^([01]\d|2[0-3]):([0-5]\d)(:[0-5]\d)?$/;
if (!timePattern.test(FormData.start_time)) {
NotifOk({
icon: 'warning',
title: 'Peringatan',
message:
'Format Jam Mulai tidak valid. Gunakan format HH:mm atau HH:mm:ss (contoh: 08:00)',
});
setConfirmLoading(false);
return;
}
if (!timePattern.test(FormData.end_time)) {
NotifOk({
icon: 'warning',
title: 'Peringatan',
message:
'Format Jam Selesai tidak valid. Gunakan format HH:mm atau HH:mm:ss (contoh: 17:00)',
});
setConfirmLoading(false); setConfirmLoading(false);
return; return;
} }
try { try {
if (FormData.shift_id) { const payload = {
// Update existing shift shift_name: formData.shift_name,
const payload = { start_time: formData.start_time,
shift_name: FormData.shift_name, end_time: formData.end_time,
start_time: FormData.start_time, is_active: formData.is_active,
end_time: FormData.end_time, };
is_active: FormData.is_active,
};
const response = await updateShift(FormData.shift_id, payload); const response =
console.log('updateShift response:', response); props.actionMode === 'edit'
? await updateShift(formData.shift_id, payload)
: await createShift(payload);
if (response.statusCode === 200) { if (response && (response.statusCode === 200 || response.statusCode === 201)) {
NotifOk({ NotifOk({ icon: 'success', title: 'Berhasil', message: `Data Shift berhasil disimpan.` });
icon: 'success', props.setActionMode('list');
title: 'Berhasil',
message: `Data Shift "${FormData.shift_name}" berhasil diubah.`,
});
props.setActionMode('list');
} else {
NotifAlert({
icon: 'error',
title: 'Gagal',
message: response.message || 'Gagal mengubah data Shift.',
});
}
} else { } else {
// Create new shift NotifOk({ icon: 'error', title: 'Gagal', message: response?.message || 'Gagal menyimpan data.' });
const payload = {
shift_name: FormData.shift_name,
start_time: FormData.start_time,
end_time: FormData.end_time,
is_active: FormData.is_active,
};
const response = await createShift(payload);
console.log('createShift response:', response);
if (response.statusCode === 200 || response.statusCode === 201) {
NotifOk({
icon: 'success',
title: 'Berhasil',
message: `Data Shift "${FormData.shift_name}" berhasil ditambahkan.`,
});
props.setActionMode('list');
} else {
NotifAlert({
icon: 'error',
title: 'Gagal',
message: response.message || 'Gagal menambahkan data Shift.',
});
}
} }
} catch (error) { } catch (error) {
console.error('Save Shift Error:', error); NotifOk({ icon: 'error', title: 'Error', message: error.message || 'Terjadi kesalahan server.' });
NotifAlert({ } finally {
icon: 'error', setConfirmLoading(false);
title: 'Error',
message: error.message || 'Terjadi kesalahan saat menyimpan data.',
});
} }
setConfirmLoading(false);
};
// Helper function to format time input
const formatTimeInput = (value) => {
if (!value) return value;
// Remove any whitespace
value = value.trim();
// If user inputs single digit hour like "8:00", convert to "08:00"
const timeRegex = /^(\d{1,2}):(\d{2})(:\d{2})?$/;
const match = value.match(timeRegex);
if (match) {
const hours = match[1].padStart(2, '0');
const minutes = match[2];
const seconds = match[3] || '';
return `${hours}:${minutes}${seconds}`;
}
return value;
}; };
const handleInputChange = (e) => { const handleInputChange = (e) => {
const { name, value } = e.target; const { name, value } = e.target;
setFormData({ ...formData, [name]: value });
// Just set the value without formatting during typing
setFormData({
...FormData,
[name]: value,
});
}; };
// Format time when user leaves the input field (onBlur) const handleTimeChange = (time, timeString, field) => {
const handleTimeBlur = (e) => { setFormData({ ...formData, [field]: timeString });
const { name, value } = e.target;
if (name === 'start_time' || name === 'end_time') {
const formattedValue = formatTimeInput(value);
setFormData({
...FormData,
[name]: formattedValue,
});
}
};
const handleStatusToggle = (isChecked) => {
setFormData({
...FormData,
is_active: isChecked,
});
};
// Helper function to extract time from ISO timestamp using dayjs
const extractTime = (timeString) => {
if (!timeString) return '';
// If it's ISO timestamp like "1970-01-01T08:00:00.000Z"
if (timeString.includes('T')) {
return dayjs.utc(timeString).format('HH:mm');
}
// If it's already in HH:mm:ss format, remove seconds
if (timeString.includes(':')) {
const parts = timeString.split(':');
return `${parts[0]}:${parts[1]}`;
}
return timeString;
}; };
useEffect(() => { useEffect(() => {
const token = localStorage.getItem('token'); if (props.selectedData) {
if (token) { setFormData(props.selectedData);
if (props.selectedData != null) { } else {
// Only set fields that are in defaultData setFormData(defaultData);
const filteredData = {
shift_id: props.selectedData.shift_id || '',
shift_name: props.selectedData.shift_name || '',
start_time: extractTime(props.selectedData.start_time) || '',
end_time: extractTime(props.selectedData.end_time) || '',
is_active: props.selectedData.is_active ?? true,
};
setFormData(filteredData);
} else {
setFormData(defaultData);
}
} }
}, [props.showModal]); }, [props.showModal, props.selectedData]);
const modalTitle = `${props.actionMode === 'add' ? 'Tambah' : props.actionMode === 'preview' ? 'Preview' : 'Edit'} Shift`;
return ( return (
<Modal <Modal
title={`${ title={modalTitle}
props.actionMode === 'add'
? 'Tambah'
: props.actionMode === 'preview'
? 'Preview'
: 'Edit'
} Shift`}
open={props.showModal} open={props.showModal}
onCancel={handleCancel} onCancel={handleCancel}
footer={[ footer={[
<> <ConfigProvider key="footer-buttons" theme={{ components: { Button: { defaultColor: '#23A55A', defaultBorderColor: '#23A55A' } } }}>
<ConfigProvider <Button key="back" onClick={handleCancel}>{props.readOnly ? 'Tutup' : 'Batal'}</Button>
theme={{ {!props.readOnly && (
token: { colorBgContainer: '#E9F6EF' }, <Button key="submit" type="primary" loading={confirmLoading} onClick={handleSave} style={{ backgroundColor: '#23a55a' }}>
components: { Simpan
Button: { </Button>
defaultBg: 'white', )}
defaultColor: '#23A55A', </ConfigProvider>,
defaultBorderColor: '#23A55A',
defaultHoverColor: '#23A55A',
},
},
}}
>
<Button onClick={handleCancel}>Batal</Button>
</ConfigProvider>
<ConfigProvider
theme={{
token: {
colorBgContainer: '#209652',
},
components: {
Button: {
defaultBg: '#23a55a',
defaultColor: '#FFFFFF',
defaultBorderColor: '#23a55a',
defaultHoverColor: '#FFFFFF',
defaultHoverBorderColor: '#23a55a',
},
},
}}
>
{!props.readOnly && (
<Button loading={confirmLoading} onClick={handleSave}>
Simpan
</Button>
)}
</ConfigProvider>
</>,
]} ]}
> >
{FormData && ( <div>
<div> <div>
{/* Status Toggle */} <Text strong>Status</Text>
<div style={{ marginBottom: 12 }}> <div style={{ display: 'flex', alignItems: 'center', marginTop: '8px' }}>
<div> <Switch
<Text strong>Status</Text> disabled={props.readOnly}
</div> style={{ backgroundColor: formData.is_active ? '#23A55A' : '#bfbfbf' }}
<div checked={formData.is_active}
style={{ onChange={(checked) => setFormData({ ...formData, is_active: checked })}
display: 'flex',
alignItems: 'center',
marginTop: '8px',
}}
>
<div style={{ marginRight: '8px' }}>
<Switch
disabled={props.readOnly}
style={{
backgroundColor:
FormData.is_active === true ? '#23A55A' : '#bfbfbf',
}}
checked={FormData.is_active === true}
onChange={handleStatusToggle}
/>
</div>
<div>
<Text>{FormData.is_active === true ? 'Active' : 'Inactive'}</Text>
</div>
</div>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Nama Shift</Text>
<Text style={{ color: 'red' }}> *</Text>
<Input
name="shift_name"
value={FormData.shift_name}
onChange={handleInputChange}
placeholder="Masukkan Nama Shift"
readOnly={props.readOnly}
/> />
</div> <Text style={{ marginLeft: '8px' }}>{formData.is_active ? 'Active' : 'Inactive'}</Text>
<div style={{ marginBottom: 12 }}>
<Text strong>Jam Mulai</Text>
<Text style={{ color: 'red' }}> *</Text>
<Input
name="start_time"
value={FormData.start_time}
onChange={handleInputChange}
placeholder="Masukkan Jam Mulai"
readOnly={props.readOnly}
maxLength={8}
/>
<Text
type="secondary"
style={{ fontSize: '12px', display: 'block', marginTop: '4px' }}
>
Contoh: 08:00 atau 08:00:00
</Text>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Jam Selesai</Text>
<Text style={{ color: 'red' }}> *</Text>
<Input
name="end_time"
value={FormData.end_time}
onChange={handleInputChange}
placeholder="Masukkan Jam Selesai"
readOnly={props.readOnly}
maxLength={8}
/>
<Text
type="secondary"
style={{ fontSize: '12px', display: 'block', marginTop: '4px' }}
>
Contoh: 17:00 atau 17:00:00
</Text>
</div> </div>
</div> </div>
)} <Divider style={{ margin: '12px 0' }} />
<div style={{ marginBottom: 12 }}>
<Text strong>Nama Shift</Text>
<Text style={{ color: 'red' }}> *</Text>
<Input
name="shift_name"
value={formData.shift_name}
onChange={handleInputChange}
placeholder="Contoh: Pagi, Sore, Malam"
readOnly={props.readOnly}
/>
</div>
<div style={{ marginBottom: 12 }}>
<Text strong>Waktu Shift</Text>
<Text style={{ color: 'red' }}> *</Text>
<Space.Compact block style={{ marginTop: '4px' }}>
<TimePicker
value={dayjs(formData.start_time, timeFormat)}
format={timeFormat}
onChange={(time, timeString) => handleTimeChange(time, timeString, 'start_time')}
style={{ width: '50%' }}
placeholder="Waktu Mulai"
disabled={props.readOnly}
/>
<TimePicker
value={dayjs(formData.end_time, timeFormat)}
format={timeFormat}
onChange={(time, timeString) => handleTimeChange(time, time-string, 'end_time')}
style={{ width: '50%' }}
placeholder="Waktu Selesai"
disabled={props.readOnly}
/>
</Space.Compact>
</div>
</div>
</Modal> </Modal>
); );
}; };
export default DetailShift; export default DetailShift;

View File

@@ -10,62 +10,46 @@ import {
import { NotifAlert, NotifConfirmDialog } from '../../../../components/Global/ToastNotif'; import { NotifAlert, NotifConfirmDialog } from '../../../../components/Global/ToastNotif';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import TableList from '../../../../components/Global/TableList'; import TableList from '../../../../components/Global/TableList';
import { getAllShift, deleteShift } from '../../../../api/master-shift'; // import { getAllShift, deleteShift } from '../../../../api/master-shift'; // <-- API needs to be created
// Helper function to extract time from ISO timestamp // Mock API calls for demonstration
const extractTime = (timeString) => { const getAllShift = async () => ({
if (!timeString) return '-'; data: [
{ shift_id: 1, shift_name: 'Pagi', start_time: '08:00', end_time: '16:00', is_active: true },
// If it's ISO timestamp like "1970-01-01T08:00:00.000Z" { shift_id: 2, shift_name: 'Sore', start_time: '16:00', end_time: '00:00', is_active: true },
if (timeString.includes('T')) { { shift_id: 3, shift_name: 'Malam', start_time: '00:00', end_time: '08:00', is_active: false },
const date = new Date(timeString); ],
const hours = String(date.getUTCHours()).padStart(2, '0'); statusCode: 200,
const minutes = String(date.getUTCMinutes()).padStart(2, '0'); });
return `${hours}:${minutes}`; const deleteShift = async (id) => ({ statusCode: 200, message: 'Data berhasil dihapus' });
}
// If it's already in HH:mm or HH:mm:ss format
if (timeString.includes(':')) {
const parts = timeString.split(':');
return `${parts[0]}:${parts[1]}`; // Return HH:mm only
}
return timeString;
};
const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
{ {
title: 'No', title: 'Shift Name',
key: 'no',
width: '5%',
align: 'center',
render: (_, __, index) => index + 1,
},
{
title: 'Nama Shift',
dataIndex: 'shift_name', dataIndex: 'shift_name',
key: 'shift_name', key: 'shift_name',
width: '20%', width: '30%',
render: (text, record, index) => `${index + 1}. ${text}`,
}, },
{ {
title: 'Jam Mulai', title: 'Start Time',
dataIndex: 'start_time', dataIndex: 'start_time',
key: 'start_time', key: 'start_time',
width: '15%', width: '15%',
render: (time) => extractTime(time), align: 'center',
}, },
{ {
title: 'Jam Selesai', title: 'End Time',
dataIndex: 'end_time', dataIndex: 'end_time',
key: 'end_time', key: 'end_time',
width: '15%', width: '15%',
render: (time) => extractTime(time), align: 'center',
}, },
{ {
title: 'Status', title: 'Status',
dataIndex: 'is_active', dataIndex: 'is_active',
key: 'is_active', key: 'is_active',
width: '10%', width: '15%',
align: 'center', align: 'center',
render: (_, { is_active }) => { render: (_, { is_active }) => {
const color = is_active ? 'green' : 'red'; const color = is_active ? 'green' : 'red';
@@ -81,36 +65,12 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
title: 'Aksi', title: 'Aksi',
key: 'aksi', key: 'aksi',
align: 'center', align: 'center',
width: '20%', width: '25%',
render: (_, record) => ( render: (_, record) => (
<Space> <Space>
<Button <Button type="text" icon={<EyeOutlined />} onClick={() => showPreviewModal(record)} style={{ color: '#1890ff' }} />
type="text" <Button type="text" icon={<EditOutlined />} onClick={() => showEditModal(record)} style={{ color: '#faad14' }} />
icon={<EyeOutlined />} <Button danger type="text" icon={<DeleteOutlined />} onClick={() => showDeleteDialog(record)} />
onClick={() => showPreviewModal(record)}
style={{
color: '#1890ff',
borderColor: '#1890ff',
}}
/>
<Button
type="text"
icon={<EditOutlined />}
onClick={() => showEditModal(record)}
style={{
color: '#faad14',
borderColor: '#faad14',
}}
/>
<Button
danger
type="text"
icon={<DeleteOutlined />}
onClick={() => showDeleteDialog(record)}
style={{
borderColor: '#ff4d4f',
}}
/>
</Space> </Space>
), ),
}, },
@@ -118,35 +78,21 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
const ListShift = memo(function ListShift(props) { const ListShift = memo(function ListShift(props) {
const [trigerFilter, setTrigerFilter] = useState(false); const [trigerFilter, setTrigerFilter] = useState(false);
const [formDataFilter, setFormDataFilter] = useState({ criteria: '' });
const defaultFilter = {
criteria: '',
};
const [formDataFilter, setFormDataFilter] = useState(defaultFilter);
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(() => { useEffect(() => {
const token = localStorage.getItem('token'); if (props.actionMode === 'list') {
if (token) { doFilter();
if (props.actionMode == 'list') {
doFilter();
}
} else {
navigate('/signin');
} }
}, [props.actionMode]); }, [props.actionMode]);
const doFilter = () => { const doFilter = () => setTrigerFilter((prev) => !prev);
setTrigerFilter((prev) => !prev);
};
const handleSearch = () => { const handleSearch = () => {
setFormDataFilter((prev) => ({ ...prev, criteria: searchValue })); setFormDataFilter((prev) => ({ ...prev, criteria: searchValue }));
doFilter(); doFilter();
}; };
const handleSearchClear = () => { const handleSearchClear = () => {
setSearchValue(''); setSearchValue('');
setFormDataFilter((prev) => ({ ...prev, criteria: '' })); setFormDataFilter((prev) => ({ ...prev, criteria: '' }));
@@ -170,135 +116,95 @@ const ListShift = memo(function ListShift(props) {
const showDeleteDialog = (param) => { const showDeleteDialog = (param) => {
NotifConfirmDialog({ NotifConfirmDialog({
icon: 'question', title: 'Konfirmasi Hapus',
title: 'Konfirmasi', message: `Apakah Anda yakin ingin menghapus shift "${param.shift_name}"?`,
message: `Apakah anda yakin hapus data "${param.shift_name}" ?`,
onConfirm: () => handleDelete(param), onConfirm: () => handleDelete(param),
onCancel: () => props.setSelectedData(null),
}); });
}; };
const handleDelete = async (param) => { const handleDelete = async (param) => {
try { try {
const response = await deleteShift(param.shift_id); const response = await deleteShift(param.shift_id);
console.log('deleteShift response:', response);
if (response.statusCode === 200) { if (response.statusCode === 200) {
NotifAlert({ NotifAlert({ icon: 'success', title: 'Berhasil', message: 'Data shift berhasil dihapus.' });
icon: 'success',
title: 'Berhasil',
message: `Data Shift "${param.shift_name}" berhasil dihapus.`,
});
// Refresh table
doFilter(); doFilter();
} else { } else {
NotifAlert({ NotifAlert({ icon: 'error', title: 'Gagal', message: response.message || 'Gagal menghapus data.' });
icon: 'error',
title: 'Gagal',
message: response.message || 'Gagal menghapus data Shift.',
});
} }
} catch (error) { } catch (error) {
console.error('Delete Shift Error:', error); NotifAlert({ icon: 'error', title: 'Error', message: error.message || 'Terjadi kesalahan server.' });
NotifAlert({
icon: 'error',
title: 'Error',
message: error.message || 'Terjadi kesalahan saat menghapus data.',
});
} }
}; };
// Function untuk dipanggil dari DetailShift setelah create/update
const refreshData = () => {
doFilter();
};
// Pass refresh function to props
if (props.setRefreshData) {
props.setRefreshData(refreshData);
}
return ( return (
<React.Fragment> <Card>
<Card> <Row justify="space-between" align="middle" gutter={[8, 8]}>
<Row> <Col xs={24}>
<Col xs={24}> <Row justify="space-between" align="middle" gutter={[8, 8]}>
<Row justify="space-between" align="middle" gutter={[8, 8]}> <Col xs={24} sm={24} md={12} lg={12}>
<Col xs={24} sm={24} md={12} lg={12}> <Input.Search
<Input.Search placeholder="Cari berdasarkan nama shift..."
placeholder="Search shift by name..." value={searchValue}
value={searchValue} onChange={(e) => {
onChange={(e) => { const value = e.target.value;
const value = e.target.value; setSearchValue(value);
setSearchValue(value); // Auto search when clearing by backspace/delete
// Auto search when clearing by backspace/delete if (value === '') {
if (value === '') { handleSearchClear();
handleSearchClear();
}
}}
onSearch={handleSearch}
allowClear
onClear={handleSearchClear}
enterButton={
<Button
type="primary"
icon={<SearchOutlined />}
style={{
backgroundColor: '#23A55A',
borderColor: '#23A55A',
}}
>
Search
</Button>
} }
size="large" }}
/> onSearch={handleSearch}
</Col> allowClear
<Col> onClear={handleSearchClear}
<Space wrap size="small"> enterButton={
<ConfigProvider <Button
theme={{ type="primary"
token: { colorBgContainer: '#E9F6EF' }, icon={<SearchOutlined />}
components: { style={{ backgroundColor: '#23A55A', borderColor: '#23A55A' }}
Button: {
defaultBg: 'white',
defaultColor: '#23A55A',
defaultBorderColor: '#23A55A',
defaultHoverColor: '#23A55A',
defaultHoverBorderColor: '#23A55A',
},
},
}}
> >
<Button Search
icon={<PlusOutlined />} </Button>
onClick={() => showAddModal()} }
size="large" size="large"
> />
Tambah Data </Col>
</Button> <Col>
</ConfigProvider> <Space wrap size="small">
</Space> <ConfigProvider
</Col> theme={{
</Row> token: { colorBgContainer: '#E9F6EF' },
</Col> components: {
<Col xs={24} sm={24} md={24} lg={24} xl={24} style={{ marginTop: '16px' }}> Button: {
<TableList defaultBg: 'white',
mobile defaultColor: '#23A55A',
cardColor={'#42AAFF'} defaultBorderColor: '#23A55A',
header={'shift_name'} defaultHoverColor: '#23A55A',
showPreviewModal={showPreviewModal} defaultHoverBorderColor: '#23A55A',
showEditModal={showEditModal} },
showDeleteDialog={showDeleteDialog} },
getData={getAllShift} }}
queryParams={formDataFilter} >
columns={columns(showPreviewModal, showEditModal, showDeleteDialog)} <Button icon={<PlusOutlined />} onClick={() => showAddModal()} size="large">
triger={trigerFilter} Tambah Data
/> </Button>
</Col> </ConfigProvider>
</Row> </Space>
</Card> </Col>
</React.Fragment> </Row>
</Col>
<Col xs={24} sm={24} md={24} lg={24} xl={24} style={{ marginTop: '16px' }}>
<TableList
mobile
cardColor={'#42AAFF'}
header={'shift_name'} // Menggunakan shift_name langsung untuk judul kartu
getData={getAllShift}
queryParams={formDataFilter}
columns={columns(showPreviewModal, showEditModal, showDeleteDialog)}
triger={trigerFilter}
/>
</Col>
</Row>
</Card>
); );
}); });

View File

@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Input, Divider, Typography, Button, ConfigProvider, InputNumber, Switch } from 'antd'; import { Modal, Input, Divider, Typography, Button, ConfigProvider, InputNumber, Switch, Row, Col } from 'antd';
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif'; import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
import { validateRun } from '../../../../Utils/validate'; import { validateRun } from '../../../../Utils/validate';
import { createStatus, updateStatus } from '../../../../api/master-status'; import { createStatus, updateStatus } from '../../../../api/master-status';
@@ -46,7 +46,6 @@ const DetailStatus = (props) => {
{ field: 'status_number', label: 'Status Number', required: true }, { field: 'status_number', label: 'Status Number', required: true },
{ field: 'status_name', label: 'Status Name', required: true }, { field: 'status_name', label: 'Status Name', required: true },
{ field: 'status_color', label: 'Status Color', required: true }, { field: 'status_color', label: 'Status Color', required: true },
{ field: 'status_description', label: 'Description', required: true },
]; ];
if ( if (
@@ -145,29 +144,35 @@ const DetailStatus = (props) => {
<Text style={{ marginLeft: 8 }}>{formData.is_active ? 'Active' : 'Inactive'}</Text> <Text style={{ marginLeft: 8 }}>{formData.is_active ? 'Active' : 'Inactive'}</Text>
</div> </div>
</div> </div>
<div style={{ marginBottom: 12 }}> <Row gutter={16}>
<Text strong>Status Number</Text> <Col span={12}>
<Text style={{ color: 'red' }}> *</Text> <div style={{ marginBottom: 12 }}>
<InputNumber <Text strong>Status Number</Text>
name="status_number" <Text style={{ color: 'red' }}> *</Text>
value={formData.status_number} <InputNumber
placeholder="Masukan nomor status" name="status_number"
readOnly={props.readOnly} value={formData.status_number}
style={{ width: '100%' }} placeholder="Masukan nomor status"
onChange={handleInputNumberChange} readOnly={props.readOnly}
/> style={{ width: '100%' }}
</div> onChange={handleInputNumberChange}
<div style={{ marginBottom: 12 }}> />
<Text strong>Status Name</Text> </div>
<Text style={{ color: 'red' }}> *</Text> </Col>
<Input <Col span={12}>
name="status_name" <div style={{ marginBottom: 12 }}>
value={formData.status_name} <Text strong>Status Name</Text>
placeholder="Masukan nama status" <Text style={{ color: 'red' }}> *</Text>
readOnly={props.readOnly} <Input
onChange={handleInputChange} name="status_name"
/> value={formData.status_name}
</div> placeholder="Masukan nama status"
readOnly={props.readOnly}
onChange={handleInputChange}
/>
</div>
</Col>
</Row>
<div style={{ marginBottom: 12 }}> <div style={{ marginBottom: 12 }}>
<Text strong>Status Color</Text> <Text strong>Status Color</Text>
<Text style={{ color: 'red' }}> *</Text> <Text style={{ color: 'red' }}> *</Text>
@@ -181,7 +186,6 @@ const DetailStatus = (props) => {
</div> </div>
<div style={{ marginBottom: 12 }}> <div style={{ marginBottom: 12 }}>
<Text strong>Description</Text> <Text strong>Description</Text>
<Text style={{ color: 'red' }}> *</Text>
<TextArea <TextArea
name="status_description" name="status_description"
value={formData.status_description} value={formData.status_description}

View File

@@ -1,98 +1,72 @@
import React, { memo } from 'react'; import React from 'react';
import { Modal, Form, Input, Select, Row, Col } from 'antd'; import { Modal, Form, Input, InputNumber, Switch, Row, Col, Typography, Divider } from 'antd';
const { TextArea } = Input; const { Text } = Typography;
const { Option } = Select;
const DetailRole = memo(function DetailRole({ const DetailRole = ({ visible, onCancel, onOk, form, editingKey, readOnly }) => {
visible, const modalTitle = editingKey ? (readOnly ? 'Preview Role' : 'Edit Role') : 'Tambah Role';
onCancel,
onOk,
form,
editingKey,
readOnly,
}) {
const getModalTitle = () => {
if (readOnly) return 'Detail Role';
if (editingKey) return 'Edit Role';
return 'Tambah Role';
};
return ( return (
<Modal <Modal
title={getModalTitle()} title={<Text style={{ fontSize: '18px' }}>{modalTitle}</Text>}
open={visible} open={visible}
onCancel={onCancel} onCancel={onCancel}
onOk={onOk} onOk={onOk}
okText={readOnly ? 'Tutup' : editingKey ? 'Simpan' : 'Tambah'} okText="Simpan"
cancelText="Batal" cancelText="Batal"
width={600} okButtonProps={{ disabled: readOnly }}
cancelButtonProps={{ style: readOnly ? { display: 'none' } : {} }} destroyOnClose
> >
<Form form={form} layout="vertical" name="roleForm" disabled={readOnly}> <Divider />
<Form form={form} layout="vertical" name="role_form">
<Form.Item
name="is_active"
label={<Text strong>Status</Text>}
valuePropName="checked"
initialValue={true}
>
<Switch disabled={readOnly} />
</Form.Item>
<Row gutter={16}> <Row gutter={16}>
<Col span={24}> <Col span={12}>
<Form.Item <Form.Item
name="role_name" name="role_name"
label="Nama Role" label={<Text strong>Nama Role</Text>}
rules={[ rules={[{ required: true, message: 'Nama Role wajib diisi!' }]}
{
required: true,
message: 'Nama role tidak boleh kosong!',
},
]}
> >
<Input placeholder="Masukkan nama role" /> <Input placeholder="Masukan nama role" readOnly={readOnly} />
</Form.Item> </Form.Item>
</Col> </Col>
</Row> <Col span={12}>
<Row gutter={16}>
<Col span={24}>
<Form.Item <Form.Item
name="role_level" name="role_level"
label="Level" label={<Text strong>Level</Text>}
rules={[ rules={[{ required: true, message: 'Level wajib diisi!' }]}
{
required: true,
message: 'Level tidak boleh kosong!',
},
]}
> >
<Select placeholder="Pilih level"> <InputNumber
<Option value={1}>Level 1</Option> placeholder="Masukan level role"
<Option value={2}>Level 2</Option> readOnly={readOnly}
<Option value={3}>Level 3</Option> style={{ width: '100%' }}
<Option value={4}>Level 4</Option>
</Select>
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={24}>
<Form.Item
name="role_description"
label="Deskripsi"
rules={[
{
required: true,
message: 'Deskripsi tidak boleh kosong!',
},
]}
>
<TextArea
rows={4}
placeholder="Masukkan deskripsi role"
maxLength={200}
showCount
/> />
</Form.Item> </Form.Item>
</Col> </Col>
</Row> </Row>
<Form.Item
name="role_description"
label={<Text strong>Deskripsi Role</Text>}
>
<Input.TextArea
rows={4}
placeholder="Masukan deskripsi (opsional)"
readOnly={readOnly}
/>
</Form.Item>
</Form> </Form>
</Modal> </Modal>
); );
}); };
export default DetailRole; export default DetailRole;