feat(core): sgw-device-ui
This commit is contained in:
60
src/pages/Trip/components/TripCancelOrFinishButton.tsx
Normal file
60
src/pages/Trip/components/TripCancelOrFinishButton.tsx
Normal 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;
|
||||
Reference in New Issue
Block a user