From edf20050db9670d2a29b1be3e359d992008fc3b8 Mon Sep 17 00:00:00 2001 From: Rafiafrzl Date: Tue, 2 Dec 2025 14:05:35 +0700 Subject: [PATCH] feat: hide tabs and improve UI elements --- src/pages/contact/component/DetailContact.jsx | 5 +- src/pages/contact/component/ListContact.jsx | 92 +++++++++++++++---- 2 files changed, 76 insertions(+), 21 deletions(-) diff --git a/src/pages/contact/component/DetailContact.jsx b/src/pages/contact/component/DetailContact.jsx index 3b6b873..d682381 100644 --- a/src/pages/contact/component/DetailContact.jsx +++ b/src/pages/contact/component/DetailContact.jsx @@ -251,7 +251,8 @@ const DetailContact = memo(function DetailContact(props) { style={{ color: formData.is_active ? '#000000' : '#ff4d4f' }} /> -
+ {/* Contact Type */} + {/*
Contact Type * -
+
*/} ); diff --git a/src/pages/contact/component/ListContact.jsx b/src/pages/contact/component/ListContact.jsx index 936361d..84ab232 100644 --- a/src/pages/contact/component/ListContact.jsx +++ b/src/pages/contact/component/ListContact.jsx @@ -1,5 +1,5 @@ import React, { memo, useState, useEffect } from 'react'; -import { Button, Row, Col, Input, Tabs, Space, ConfigProvider, Card, Tag } from 'antd'; +import { Button, Row, Col, Input, Tabs, Space, ConfigProvider, Card, Tag, Switch } from 'antd'; import { PlusOutlined, EditOutlined, @@ -10,9 +10,43 @@ import { } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom'; import { NotifAlert, NotifConfirmDialog } from '../../../components/Global/ToastNotif'; -import { getAllContact, deleteContact } from '../../../api/contact'; +import { getAllContact, deleteContact, updateContact } from '../../../api/contact'; + +const ContactCard = memo(function ContactCard({ + contact, + showEditModal, + showDeleteModal, + onStatusToggle, +}) { + const handleStatusToggle = async (checked) => { + try { + const updatedContact = { + contact_name: contact.contact_name || contact.name, + contact_phone: contact.contact_phone || contact.phone, + is_active: checked, + contact_type: contact.contact_type, + }; + + await updateContact(contact.contact_id || contact.id, updatedContact); + + NotifAlert({ + icon: 'success', + title: 'Berhasil', + message: `Status "${contact.contact_name || contact.name}" berhasil diperbarui.`, + }); + + // Refresh contacts list + onStatusToggle && onStatusToggle(); + } catch (error) { + console.error('Error updating contact status:', error); + NotifAlert({ + icon: 'error', + title: 'Error', + message: 'Gagal memperbarui status kontak', + }); + } + }; -const ContactCard = memo(function ContactCard({ contact, showEditModal, showDeleteModal }) { return (
{/* Type Badge - Top Left */} -
+ {/*
{contact.contact_type === 'operator' ? 'Operator' : contact.contact_type === 'gudang' ? 'Gudang' : 'Unknown'} -
+
*/} - {/* Status Badge - Top Right */} -
- {contact.status === 'active' ? ( - - Active - - ) : ( - - InActive - - )} + {/* Status Slider - Top Right */} +
+
+ + + {contact.status === 'active' ? 'Active' : 'Inactive'} + +
{/* Main Content */} @@ -316,7 +368,7 @@ const ListContact = memo(function ListContact(props) { { const value = e.target.value; @@ -382,7 +434,8 @@ const ListContact = memo(function ListContact(props) { marginBottom: '16px', }} > - + /> */}
{getFilteredContacts().length === 0 ? ( @@ -423,6 +476,7 @@ const ListContact = memo(function ListContact(props) { }} showEditModal={showEditModal} showDeleteModal={showDeleteModal} + onStatusToggle={fetchContacts} /> ))}