feat(core): sgw-device-ui

This commit is contained in:
Tran Anh Tuan
2025-09-26 18:22:04 +07:00
parent 466e931537
commit 2707b92f7e
88 changed files with 19104 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import { updateTripState } from '@/services/controller/TripController';
import { useModel } from '@umijs/max';
import { Button, message, Popconfirm } from 'antd';
import React from 'react';
import CancelTrip from './CancelTrip';
interface TripCancleOrFinishedButtonProps {
tripStatus?: number;
onCallBack?: (success: boolean) => void;
}
const TripCancleOrFinishedButton: React.FC<TripCancleOrFinishedButtonProps> = ({
tripStatus,
onCallBack,
}) => {
const { getApi } = useModel('getTrip');
const handleClickButton = async (state: number, note?: string) => {
try {
const resp = await updateTripState({ status: state, note: note || '' });
message.success('Cập nhật trạng thái thành công');
getApi();
onCallBack?.(true);
} catch (error) {
console.error('Error updating trip status:', error);
message.error('Cập nhật trạng thái thất bại');
onCallBack?.(false);
}
};
const renderButton = () => {
switch (tripStatus) {
case 3: // Đang hoạt động
return (
<div className="flex gap-3">
<CancelTrip
onFinished={async (note) => {
await handleClickButton(5, note);
}}
/>
<Popconfirm
title="Thông báo"
description="Bạn chắc chắn muốn kết thúc chuyến đi?"
onConfirm={async () => handleClickButton(4)}
okText="Chắc chắn"
cancelText="Không"
>
<Button color="orange" variant="solid">
Kết thúc
</Button>
</Popconfirm>
</div>
);
default:
return null;
}
};
return <div>{renderButton()}</div>;
};
export default TripCancleOrFinishedButton;