ebanutsya

This commit is contained in:
2023-11-06 07:23:11 +03:00
parent 2a4479faac
commit f015090143
18 changed files with 400 additions and 108 deletions

View File

@@ -21,6 +21,7 @@ const ReprintModal: FC = () => {
dispatch(closeReprintModal());
dispatch(openLoadingModal());
PrintingApi.getLabel(order.databaseId).then(pdfBytes => {
PrintingService.getInstance().printPdf(printerName, pdfBytes).then(r => {
dispatch(closeLoadingModal());
if (r) dispatch(closeReprintModal());

View File

@@ -3,11 +3,22 @@ import {BottomSheetModal} from "@gorhom/bottom-sheet";
import {disableDim, enableDim} from "../../../features/interface/interfaceSlice";
import {StyleSheet, View} from "react-native";
import BasicButton from "../../BasicButton/BasicButton";
import {useDispatch} from "react-redux";
import {useDispatch, useSelector} from "react-redux";
import {RFPercentage} from "react-native-responsive-fontsize";
import RadioGroup from 'react-native-radio-buttons-group';
import {responsiveHeight, responsiveWidth} from "react-native-responsive-dimensions";
import {blue} from "../../../css/colors";
import {Picker} from "@react-native-picker/picker";
import DateTimePicker from '@react-native-community/datetimepicker';
import {RootState} from "../../../redux/store";
import {
closeOrdersFilterModal,
OrderStatus,
orderStatuses,
setDesc,
setOrderBy, setShipmentDate, setStatus
} from "../../../features/ordersFilter/ordersFilterSlice";
import {retry} from "@reduxjs/toolkit/query";
export type SortingModalHandles = {
present: () => void;
@@ -19,12 +30,7 @@ export type SortingModalElement = {
label: string;
value: string;
}
type Props = {
onChange: (sortingValue: string) => void;
onClose: () => void;
elements: SortingModalElement[];
defaultElementId?: string;
};
const createRadioButton = (element: SortingModalElement) => {
return {
@@ -41,55 +47,101 @@ const createRadioButton = (element: SortingModalElement) => {
};
}
const SortingModal = forwardRef<SortingModalHandles, Props>((props: Props, ref) => {
const {elements, onChange, onClose, defaultElementId = ""} = props;
const snapPoints = useMemo(() => ['40%', '40%'], []);
const SortingModal = () => {
const state = useSelector((state: RootState) => state.ordersFilter);
const elements = [
{id: 'createdOnAsc', value: 'createdOnAsc', label: 'Дата создания по возрастанию'},
{id: 'createdOnDesc', value: 'createdOnDesc', label: 'Дата создания по убыванию'},
{id: 'shipmentDateAsc', value: 'shipmentDateAsc', label: 'Дата отгрузки по возрастанию'},
{id: 'shipmentDateDesc', value: 'shipmentDateDesc', label: 'Дата отгрузки по убыванию'},
];
const [showShipmentPicker, setShowShipmentPicker] = useState(false);
const snapPoints = useMemo(() => ['60%', '60%'], []);
const dispatch = useDispatch();
const modalRef = useRef<BottomSheetModal>(null);
const dismiss = () => {
if (!modalRef.current) return;
dispatch(disableDim());
modalRef.current.dismiss();
onClose();
}
const present = () => {
if (!modalRef.current) return;
modalRef.current.present();
dispatch(enableDim());
}
useImperativeHandle(ref, () => ({
present: present,
dismiss: dismiss
}));
const [selectedId, setSelectedId] = useState<string>(defaultElementId);
useEffect(() => {
onChange(selectedId);
}, [selectedId]);
if (state.isVisible) present();
else dismiss();
}, [state.isVisible]);
return (
<BottomSheetModal
ref={modalRef}
snapPoints={snapPoints}
onDismiss={() => {
dispatch(disableDim());
dispatch(closeOrdersFilterModal())
}}>
<View style={styles.container}>
<View style={styles.content}>
<RadioGroup selectedId={selectedId}
onPress={setSelectedId}
<RadioGroup selectedId={state.orderBy + (state.desc ? "Desc" : "Asc")}
onPress={(event) => {
const orderRegex = /(Asc|Desc)$/;
const orderMatch = event.match(orderRegex);
if (!orderMatch) return;
const isDesc = orderMatch[0] === 'Desc';
const orderByField = event.replace(orderRegex, '');
if (!["createdOn", "shipmentDate"].includes(orderByField)) return
dispatch(setDesc(isDesc));
dispatch(setOrderBy(orderByField as "createdOn" | "shipmentDate"));
}}
containerStyle={styles.radioButtons}
radioButtons={elements.map(createRadioButton)}/>
<View style={{
borderWidth: responsiveWidth(0.1),
borderRadius: responsiveWidth(1)
}}>
<Picker selectedValue={state.status}
onValueChange={(value, event) => dispatch(setStatus(value))}>
{orderStatuses.map((status) => {
return (
<Picker.Item
key={status.key}
label={status.label}
value={status.key}
style={{fontSize: responsiveWidth(3)}}
/>
)
})}
</Picker>
</View>
<BasicButton onPress={() => setShowShipmentPicker(oldValue => !oldValue)}
label={"Выбрать дату отгрузки"}/>
{showShipmentPicker &&
<DateTimePicker value={new Date(state.shipmentDate)}
onChange={(event) => {
if (!event.nativeEvent.timestamp) return;
setShowShipmentPicker(false);
if (event.type === 'set') {
const selectedDate = new Date(event.nativeEvent.timestamp);
dispatch(setShipmentDate(selectedDate.toISOString()));
}
}}/>}
</View>
<BasicButton label={"Закрыть"} style={styles.button} onPress={() => {
dismiss();
dispatch(closeOrdersFilterModal());
}}/>
</View>
</BottomSheetModal>
);
});
)
};
const styles = StyleSheet.create({
container: {
width: "100%",
@@ -97,13 +149,17 @@ const styles = StyleSheet.create({
flex: 1,
padding: RFPercentage(3),
flexDirection: "column",
justifyContent: "space-between"
justifyContent: "space-between",
rowGap: responsiveHeight(1)
},
radioButtons: {
alignItems: "flex-start"
},
content: {},
content: {
rowGap: responsiveHeight(1)
},
button: {
marginTop: "auto"
},

View File

@@ -4,10 +4,11 @@ import {RFPercentage} from "react-native-responsive-fontsize";
import DText from "../DText/DText";
import {responsiveHeight, responsiveWidth} from "react-native-responsive-dimensions";
import DTitle from "../DTitle/DTitle";
import {Order} from "../../types/order";
import {BaseMarketplace, Order} from "../../types/order";
import OrderProductsList from "./OrderProductsList";
import {useDispatch} from "react-redux";
import {setOrder} from "../../features/assembly/assemblySlice";
import {OrderStatus, OrderStatusDictionary} from "../../features/ordersFilter/ordersFilterSlice";
type Props = {
onPress?: (event: GestureResponderEvent) => void
@@ -15,9 +16,17 @@ type Props = {
onSelect: (order: Order) => void
}
const BaseMarketplaceIconDict = {
[BaseMarketplace.Wildberries]: require('assets/icons/marketplaces/wildberries.png'),
[BaseMarketplace.Ozon]: require('assets/icons/marketplaces/ozon.png'),
[BaseMarketplace.YandexMarket]: require('assets/icons/marketplaces/yandex_market.png'),
};
const OrderCard: FC<Props> = ({onPress, onSelect, order}) => {
return (
<TouchableOpacity onPress={()=>{
<TouchableOpacity onPress={() => {
if (onSelect) onSelect(order);
}}>
@@ -26,7 +35,7 @@ const OrderCard: FC<Props> = ({onPress, onSelect, order}) => {
<View style={styles.title}>
<DTitle>{order.orderNumber}</DTitle>
<Image source={require('assets/icons/marketplaces/ozon.png')} style={styles.titleImage}/>
<Image source={BaseMarketplaceIconDict[order.baseMarketplace]} style={styles.titleImage}/>
</View>
<DText>Селлер: {order.sellerName}</DText>
<DText>Маркетплейс: {order.marketplaceName}</DText>
@@ -34,7 +43,7 @@ const OrderCard: FC<Props> = ({onPress, onSelect, order}) => {
</View>
<View style={styles.descriptionStatus}>
<DText>
Ожидает сборки
{OrderStatusDictionary[order.status as OrderStatus]}
</DText>
</View>
</View>

View File

@@ -9,16 +9,16 @@ import {background} from "../../css/colors";
type ListProps = {
products: OrderProduct[];
onSelected: (product: OrderProduct) => void;
onSelected: (product: number) => void;
}
type CardProps = {
product: OrderProduct;
onPress: (product: OrderProduct) => void;
onPress: (product: number) => void;
id: number;
}
const OrderProductCard: FC<CardProps> = ({product, onPress, id}) => {
return (
<TouchableOpacity onPress={() => onPress(product)}>
<TouchableOpacity onPress={() => onPress(id)}>
<View style={cardStyles.container}>
<View style={cardStyles.content}>
<DText>{id + 1}) {product.productName}</DText>

View File

@@ -7,16 +7,15 @@ import SelectProductModal from "../Modals/SelectProductModal/SelectProductModal"
import {SupplierProduct} from "../../types/supplierProduct";
import barcodeApi from "../../api/barcodeApi";
import {useDispatch, useSelector} from "react-redux";
import {openScanModal} from "../../features/scanModal/scanModalSlice";
import {openScanModal, setScannedData} from "../../features/scanModal/scanModalSlice";
import {RootState} from "../../redux/store";
type Props = {
onSearch: (text: string) => void;
onSearch?: (text: string) => void;
onSupplierProductSelected?: (supplierProduct: SupplierProduct) => void
}
const SearchBar: FC<Props> = ({onSearch, onSupplierProductSelected}) => {
// const [isScanModalVisible, setIsScanModalVisible] = useState<boolean>(false);
// const [, setSelectProductModalVisible] = useState(false);
const dispatch = useDispatch();
const [searchInput, setSearchInput] = useState<string>("");
const textInputRef = useRef<TextInput>(null);
@@ -26,19 +25,19 @@ const SearchBar: FC<Props> = ({onSearch, onSupplierProductSelected}) => {
useEffect(() => {
if (!scannedData) return;
barcodeApi.searchProducts(scannedData).then((response) => {
console.log("Response: " + response);
setProducts(response)
});
}, [scannedData]);
const selectProductModalVisible = products.length > 0;
return (
<View style={styles.container}>
<SelectProductModal visible={selectProductModalVisible} products={products} onSelected={(product) => {
if (onSupplierProductSelected) onSupplierProductSelected(product);
setProducts([]);
dispatch(setScannedData(undefined));
}}/>
<BasicButton onPress={() => {
if (!onSearch) return;
onSearch(searchInput);
if (textInputRef.current) {
textInputRef.current.clear();
@@ -77,7 +76,7 @@ const styles = StyleSheet.create({
borderTopRightRadius: responsiveWidth(1),
borderBottomRightRadius: responsiveWidth(1),
paddingHorizontal: responsiveWidth(5),
height:'100%'
height: '100%'
},
scanImageWrapper: {
paddingHorizontal: responsiveWidth(1),