feat: add confirmCurrent method to assemblyApi and enhance BarcodeScreen functionality
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import apiClient from "./apiClient";
|
import apiClient from "./apiClient";
|
||||||
import {Assembly} from "../types/assembly";
|
import {Assembly} from "../types/assembly";
|
||||||
import {closeCancelAssemblyModal} from "../features/cancelAssemblyModal/cancelAssemblyModalSlice";
|
|
||||||
|
|
||||||
const router = '/assembly';
|
const router = '/assembly';
|
||||||
export type CreateAssemblyResponse = {
|
export type CreateAssemblyResponse = {
|
||||||
@@ -39,6 +38,10 @@ const assemblyApi = {
|
|||||||
let response = await apiClient.post(`${router}/confirm`, {assemblyId});
|
let response = await apiClient.post(`${router}/confirm`, {assemblyId});
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
confirmCurrent: async (): Promise<{ ok: boolean, message: string }> => {
|
||||||
|
let response = await apiClient.post(`${router}/confirmCurrent`);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
cancelById: async (assemblyId: number): Promise<{ ok: boolean, message: string }> => {
|
cancelById: async (assemblyId: number): Promise<{ ok: boolean, message: string }> => {
|
||||||
let response = await apiClient.post(`${router}/cancelById`, {assemblyId});
|
let response = await apiClient.post(`${router}/cancelById`, {assemblyId});
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|||||||
BIN
src/assets/icons/settings/check.png
Normal file
BIN
src/assets/icons/settings/check.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -221,9 +221,7 @@ const ConfirmedButtons = () => {
|
|||||||
dispatch(showReward({reward}));
|
dispatch(showReward({reward}));
|
||||||
dispatch(fetchBalance())
|
dispatch(fetchBalance())
|
||||||
dispatch(refreshTransactions())
|
dispatch(refreshTransactions())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(endAssembly());
|
dispatch(endAssembly());
|
||||||
navigator.navigate('Barcode');
|
navigator.navigate('Barcode');
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import AssemblyControls from "./AssemblyControls";
|
|||||||
import AcceptAssemblyModal from "./AcceptAssemblyModal";
|
import AcceptAssemblyModal from "./AcceptAssemblyModal";
|
||||||
import assemblyApi, {CreateAssemblyResponse} from "../../api/assemblyApi";
|
import assemblyApi, {CreateAssemblyResponse} from "../../api/assemblyApi";
|
||||||
import {setAssembly, startAssembly} from "../../features/assembly/assemblySlice";
|
import {setAssembly, startAssembly} from "../../features/assembly/assemblySlice";
|
||||||
import {ScanCrptContextProvider} from "./contexts/ScanCrptContext";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
order: Order;
|
order: Order;
|
||||||
@@ -32,7 +31,8 @@ const AssemblyView = (props: Props) => {
|
|||||||
<View style={styles.viewContainer}>
|
<View style={styles.viewContainer}>
|
||||||
<View style={styles.topSection}>
|
<View style={styles.topSection}>
|
||||||
<AssemblyProductSelect order={order}/>
|
<AssemblyProductSelect order={order}/>
|
||||||
<ProductImageView imageUrl={state.selectedProduct?.imageUrl}/>
|
<ProductImageView
|
||||||
|
imageUrl={state.selectedProduct ? state.selectedProduct.imageUrl : order.products[0].imageUrl}/>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.bottomSection}>
|
<View style={styles.bottomSection}>
|
||||||
<OrderInfoView
|
<OrderInfoView
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import {Button, StyleSheet, Text, View} from "react-native";
|
import {StyleSheet, View} from "react-native";
|
||||||
import {RootState, useAppDispatch} from "../../redux/store";
|
import {RootState} from "../../redux/store";
|
||||||
import * as process from "process";
|
|
||||||
import {responsiveHeight, responsiveWidth} from "react-native-responsive-dimensions";
|
import {responsiveHeight, responsiveWidth} from "react-native-responsive-dimensions";
|
||||||
import SearchBar from "../../components/SearchBar/SearchBar";
|
import SearchBar from "../../components/SearchBar/SearchBar";
|
||||||
import {useDispatch, useSelector} from "react-redux";
|
import {useDispatch, useSelector} from "react-redux";
|
||||||
import {NavigationProp, useFocusEffect, useNavigation, useNavigationState} from "@react-navigation/native";
|
import {NavigationProp, useNavigation, useNavigationState} from "@react-navigation/native";
|
||||||
import {TabNavigatorParamList} from "../MainScreen/MainScreen";
|
import {TabNavigatorParamList} from "../MainScreen/MainScreen";
|
||||||
import {FlashList} from "@shopify/flash-list";
|
import {FlashList} from "@shopify/flash-list";
|
||||||
import {Order} from "../../types/order";
|
import {Order} from "../../types/order";
|
||||||
@@ -13,9 +12,7 @@ import {setOrder} from "../../features/assembly/assemblySlice";
|
|||||||
import flashListSeparator from "../../components/FlashListSeparator/FlashListSeparator";
|
import flashListSeparator from "../../components/FlashListSeparator/FlashListSeparator";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {openScanModal} from "../../features/scanModal/scanModalSlice";
|
import {openScanModal} from "../../features/scanModal/scanModalSlice";
|
||||||
import ordersApi from "../../api/ordersApi";
|
|
||||||
import DTitle from "../../components/DTitle/DTitle";
|
import DTitle from "../../components/DTitle/DTitle";
|
||||||
import {useNormalizedSnapPoints} from "@gorhom/bottom-sheet/lib/typescript/hooks";
|
|
||||||
import SortingButton from "../../components/SortingButton/SortingButton";
|
import SortingButton from "../../components/SortingButton/SortingButton";
|
||||||
import useBarcodeOrders from "./useBarcodeOrders";
|
import useBarcodeOrders from "./useBarcodeOrders";
|
||||||
import {openOrdersFilterModal} from "../../features/ordersFilter/ordersFilterSlice";
|
import {openOrdersFilterModal} from "../../features/ordersFilter/ordersFilterSlice";
|
||||||
@@ -23,15 +20,17 @@ import {openOrdersFilterModal} from "../../features/ordersFilter/ordersFilterSli
|
|||||||
function BarcodeScreen() {
|
function BarcodeScreen() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [productId, setProductId] = useState(-1);
|
const [productId, setProductId] = useState(-1);
|
||||||
const {orders, isUpdating} = useBarcodeOrders({productId});
|
const {orders, isUpdating,refresh} = useBarcodeOrders({productId});
|
||||||
|
|
||||||
const isScanModalVisible = useSelector((state: RootState) => state.scanModal.isVisible);
|
const isScanModalVisible = useSelector((state: RootState) => state.scanModal.isVisible);
|
||||||
const navigator = useNavigation<NavigationProp<TabNavigatorParamList, 'Home'>>();
|
const navigator = useNavigation<NavigationProp<TabNavigatorParamList, 'Home'>>();
|
||||||
const navigationState = useNavigationState((state) => state);
|
const navigationState = useNavigationState((state) => state);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("state changed")
|
|
||||||
if (!navigationState.history) return;
|
if (!navigationState.history) return;
|
||||||
|
if (productId < 0) return;
|
||||||
|
console.log('refreshing orders for productId:', productId);
|
||||||
|
refresh();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let currentTabKey: string = navigationState.history[navigationState.history.length - 1].key;
|
let currentTabKey: string = navigationState.history[navigationState.history.length - 1].key;
|
||||||
if (currentTabKey.startsWith("Barcode")) if (!isScanModalVisible) dispatch(openScanModal({}));
|
if (currentTabKey.startsWith("Barcode")) if (!isScanModalVisible) dispatch(openScanModal({}));
|
||||||
@@ -49,6 +48,7 @@ function BarcodeScreen() {
|
|||||||
{orders.length > 0 || isUpdating ? <FlashList
|
{orders.length > 0 || isUpdating ? <FlashList
|
||||||
refreshing={isUpdating}
|
refreshing={isUpdating}
|
||||||
onRefresh={() => {
|
onRefresh={() => {
|
||||||
|
refresh()
|
||||||
}}
|
}}
|
||||||
keyboardShouldPersistTaps={"never"}
|
keyboardShouldPersistTaps={"never"}
|
||||||
data={orders}
|
data={orders}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import {RootState} from "../../redux/store";
|
|||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {Order} from "../../types/order";
|
import {Order} from "../../types/order";
|
||||||
import ordersApi from "../../api/ordersApi";
|
import ordersApi from "../../api/ordersApi";
|
||||||
import {setOrderBy} from "../../features/ordersFilter/ordersFilterSlice";
|
|
||||||
import {setOrder} from "../../features/assembly/assemblySlice";
|
|
||||||
|
|
||||||
export type Props = {
|
export type Props = {
|
||||||
productId: number;
|
productId: number;
|
||||||
@@ -23,16 +21,19 @@ const useBarcodeOrders = (props: Props) => {
|
|||||||
city
|
city
|
||||||
} = useSelector((state: RootState) => state.ordersFilter);
|
} = useSelector((state: RootState) => state.ordersFilter);
|
||||||
const fetchOrders = async (): Promise<Order[]> => {
|
const fetchOrders = async (): Promise<Order[]> => {
|
||||||
return ordersApi.getOrdersByProduct({productId, orderBy, shipmentDate, status, shippingWarehouse,city, desc});
|
return ordersApi.getOrdersByProduct({productId, orderBy, shipmentDate, status, shippingWarehouse, city, desc});
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
const refresh = () => {
|
||||||
if (isVisible || productId < 0) return;
|
|
||||||
setOrders([]);
|
setOrders([]);
|
||||||
setIsUpdating(true);
|
setIsUpdating(true);
|
||||||
fetchOrders().then((fetchedOrders) => {
|
fetchOrders().then((fetchedOrders) => {
|
||||||
setOrders(fetchedOrders);
|
setOrders(fetchedOrders);
|
||||||
setIsUpdating(false);
|
setIsUpdating(false);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
useEffect(() => {
|
||||||
|
if (isVisible || productId < 0) return;
|
||||||
|
refresh()
|
||||||
}, [
|
}, [
|
||||||
productId,
|
productId,
|
||||||
isVisible,
|
isVisible,
|
||||||
@@ -40,9 +41,14 @@ const useBarcodeOrders = (props: Props) => {
|
|||||||
orderBy,
|
orderBy,
|
||||||
shipmentDate,
|
shipmentDate,
|
||||||
status,
|
status,
|
||||||
shippingWarehouse]);
|
shippingWarehouse,
|
||||||
|
]);
|
||||||
|
|
||||||
return {orders, isUpdating}
|
return {
|
||||||
|
orders,
|
||||||
|
refresh,
|
||||||
|
isUpdating
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useBarcodeOrders;
|
export default useBarcodeOrders;
|
||||||
@@ -37,9 +37,6 @@ const SettingsView: FC = () => {
|
|||||||
showsHorizontalScrollIndicator={false}
|
showsHorizontalScrollIndicator={false}
|
||||||
contentContainerStyle={styles.actionsCarousel}
|
contentContainerStyle={styles.actionsCarousel}
|
||||||
>
|
>
|
||||||
<SettingsElement icon={require('assets/icons/settings/withdraw.png')} title={'Вывод'}/>
|
|
||||||
<SettingsElement icon={require('assets/icons/settings/statistics.png')} title={'Статистика'}/>
|
|
||||||
<SettingsElement icon={require('assets/icons/settings/printer.png')} title={'Принтеры'}/>
|
|
||||||
<SettingsElement onPress={() => {
|
<SettingsElement onPress={() => {
|
||||||
assemblyApi.cancel().then(response => {
|
assemblyApi.cancel().then(response => {
|
||||||
|
|
||||||
@@ -51,6 +48,17 @@ const SettingsView: FC = () => {
|
|||||||
dispatch(reset());
|
dispatch(reset());
|
||||||
})
|
})
|
||||||
}} icon={require('assets/icons/settings/close.png')} title={'Отменить сборку'}/>
|
}} icon={require('assets/icons/settings/close.png')} title={'Отменить сборку'}/>
|
||||||
|
<SettingsElement onPress={() => {
|
||||||
|
assemblyApi.confirmCurrent().then(response => {
|
||||||
|
|
||||||
|
Toast.show({
|
||||||
|
type: response.ok ? "success" : "error",
|
||||||
|
text1: "Закрытие сборки",
|
||||||
|
text2: response.message,
|
||||||
|
});
|
||||||
|
dispatch(reset());
|
||||||
|
})
|
||||||
|
}} icon={require('assets/icons/settings/check.png')} title={'Закрыть сборку'}/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user