refactor(typings): Refactor user and profile models; update API response types
This commit is contained in:
@@ -61,7 +61,7 @@ const ShipDetail = ({
|
||||
|
||||
let shipOwner:
|
||||
| MasterModel.UserResponse
|
||||
| MasterModel.ProfileResponse
|
||||
| MasterModel.UserResponse
|
||||
| null = null;
|
||||
if (resp?.owner_id) {
|
||||
if (initialState?.currentUserProfile?.metadata?.user_type === 'admin') {
|
||||
|
||||
@@ -206,7 +206,7 @@ const MapPage = () => {
|
||||
? ''
|
||||
: [stateCriticalQuery, stateSosQuery].filter(Boolean).join(',');
|
||||
let metaFormQuery: Record<string, any> = {};
|
||||
if (stateQuery?.isDisconected)
|
||||
if (stateQuery?.isDisconnected)
|
||||
metaFormQuery = { ...metaFormQuery, connected: false };
|
||||
const metaStateQuery =
|
||||
stateQueryParams !== '' ? { state_level: stateQueryParams } : null;
|
||||
@@ -252,7 +252,7 @@ const MapPage = () => {
|
||||
};
|
||||
|
||||
setThings(null);
|
||||
const resp = await apiSearchThings(metaQuery);
|
||||
const resp = await apiSearchThings(metaQuery, 'sgw');
|
||||
return resp;
|
||||
} catch (error) {
|
||||
console.error('Error when searchThings: ', error);
|
||||
|
||||
@@ -58,7 +58,7 @@ export type TagStateCallbackPayload = {
|
||||
isWarning: boolean;
|
||||
isCritical: boolean;
|
||||
isSos: boolean;
|
||||
isDisconected: boolean; // giữ đúng theo yêu cầu (1 'n')
|
||||
isDisconnected: boolean; // giữ đúng theo yêu cầu (1 'n')
|
||||
};
|
||||
|
||||
export type PointData = {
|
||||
@@ -82,7 +82,7 @@ export interface GPSParseResult {
|
||||
|
||||
export interface ShipDetailData {
|
||||
ship: SgwModel.ShipDetail;
|
||||
owner: MasterModel.ProfileResponse | null;
|
||||
owner: MasterModel.UserResponse | null;
|
||||
gps: GPSParseResult | null;
|
||||
trip_id?: string;
|
||||
zone_entered_alarm_list: ZoneAlarmParse[];
|
||||
|
||||
@@ -13,7 +13,7 @@ interface EditModalProps {
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onFinish: (
|
||||
values: Pick<MasterModel.Thing, 'name'> &
|
||||
Pick<MasterModel.ThingMetadata, 'address' | 'external_id'>,
|
||||
Pick<MasterModel.ThingReponseMetadata, 'address' | 'external_id'>,
|
||||
) => Promise<boolean>;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,18 @@ interface CreateTripProps {
|
||||
thing_id?: string;
|
||||
}
|
||||
|
||||
interface TripFormValues {
|
||||
name: string;
|
||||
departure_time: any; // dayjs object or string
|
||||
departure_port_id: number;
|
||||
arrival_time?: any; // dayjs object or string
|
||||
arrival_port_id?: number;
|
||||
fishing_ground_codes?: number[];
|
||||
fishing_gear?: SgwModel.FishingGear[];
|
||||
trip_cost?: SgwModel.TripCost[];
|
||||
ship_id?: string;
|
||||
}
|
||||
|
||||
const CreateTrip: React.FC<CreateTripProps> = ({ onSuccess, thing_id }) => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [selectedThing, setSelectedThing] = useState<string | undefined>();
|
||||
@@ -41,9 +53,9 @@ const CreateTrip: React.FC<CreateTripProps> = ({ onSuccess, thing_id }) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [lastTrip, setLastTrip] = useState<SgwModel.Trip | null>(null);
|
||||
const [initialFormValues, setInitialFormValues] = useState<
|
||||
Partial<SgwModel.TripFormValues>
|
||||
Partial<TripFormValues>
|
||||
>({});
|
||||
const formRef = useRef<ProFormInstance<SgwModel.TripFormValues>>(null);
|
||||
const formRef = useRef<ProFormInstance<TripFormValues>>(null);
|
||||
const { homeports, getHomeportsByProvinceCode } = useModel(
|
||||
'slave.sgw.useHomePorts',
|
||||
);
|
||||
@@ -125,7 +137,7 @@ const CreateTrip: React.FC<CreateTripProps> = ({ onSuccess, thing_id }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (values: SgwModel.TripFormValues) => {
|
||||
const handleSubmit = async (values: TripFormValues) => {
|
||||
try {
|
||||
if (!selectedShip) {
|
||||
message.error('Vui lòng chọn tàu!');
|
||||
@@ -155,7 +167,7 @@ const CreateTrip: React.FC<CreateTripProps> = ({ onSuccess, thing_id }) => {
|
||||
.filter((n: number) => !isNaN(n))
|
||||
: [],
|
||||
fishing_gears: values.fishing_gear,
|
||||
trip_cost: values.trip_cost,
|
||||
trip_cost: values.trip_cost || [],
|
||||
};
|
||||
|
||||
const thingIdToUse = selectedShip.thing_id || selectedThing;
|
||||
@@ -211,7 +223,7 @@ const CreateTrip: React.FC<CreateTripProps> = ({ onSuccess, thing_id }) => {
|
||||
>
|
||||
<StepsForm<SgwModel.TripCreateParams>
|
||||
stepsProps={{ size: 'small' }}
|
||||
onFinish={handleSubmit}
|
||||
onFinish={(values) => handleSubmit(values as TripFormValues)}
|
||||
submitter={{
|
||||
render: (_: SubmitterProps, dom) => dom,
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user