cities filter
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import apiClient from "./apiClient";
|
||||
import {ShippingWarehouse} from "../types/shippingWarehouse";
|
||||
import {City} from "../types/city";
|
||||
|
||||
const router = '/general';
|
||||
|
||||
@@ -8,5 +9,9 @@ const generalApi = {
|
||||
let response = await apiClient.get(`${router}/getShippingWarehouses`);
|
||||
return response.data;
|
||||
},
|
||||
getCities: async (): Promise<City[]> => {
|
||||
let response = await apiClient.get(`${router}/getCities`);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
export default generalApi;
|
||||
@@ -3,6 +3,7 @@ import {Order} from "../types/order";
|
||||
import * as inspector from "inspector";
|
||||
import {OrderStatus} from "../features/ordersFilter/ordersFilterSlice";
|
||||
import {ShippingWarehouse} from "../types/shippingWarehouse";
|
||||
import {City} from "../types/city";
|
||||
|
||||
const router = '/orders';
|
||||
|
||||
@@ -25,12 +26,14 @@ const ordersApi = {
|
||||
desc: boolean,
|
||||
status: OrderStatus,
|
||||
shipmentDate: string,
|
||||
shippingWarehouse: ShippingWarehouse
|
||||
shippingWarehouse: ShippingWarehouse,
|
||||
city: City
|
||||
}): Promise<Order[]> => {
|
||||
let response = await apiClient.get(`${router}/getByProductId`, {
|
||||
params: {
|
||||
...params,
|
||||
shippingWarehouse: params.shippingWarehouse.id
|
||||
shippingWarehouse: params.shippingWarehouse.id,
|
||||
city: params.city.id
|
||||
}
|
||||
});
|
||||
return response.data;
|
||||
|
||||
42
src/components/CitySelect/CitySelect.tsx
Normal file
42
src/components/CitySelect/CitySelect.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import {FC, useEffect} from "react";
|
||||
import {useDispatch, useSelector} from "react-redux";
|
||||
import {RootState} from "../../redux/store";
|
||||
import {Picker} from "@react-native-picker/picker";
|
||||
import generalApi from "../../api/generalApi";
|
||||
|
||||
import {responsiveWidth} from "react-native-responsive-dimensions";
|
||||
import {View} from "react-native";
|
||||
import {initializeCitySelect, selectCity} from "../../features/citySelect/citySelectSlice";
|
||||
|
||||
const CitySelect: FC = () => {
|
||||
const state = useSelector((state: RootState) => state.citySelect);
|
||||
const dispatch = useDispatch();
|
||||
useEffect(() => {
|
||||
if (state.initialized) return;
|
||||
generalApi.getCities().then(cities =>
|
||||
dispatch(initializeCitySelect(cities)))
|
||||
}, []);
|
||||
return (
|
||||
<View style={{
|
||||
borderWidth: responsiveWidth(0.1),
|
||||
borderRadius: responsiveWidth(1)
|
||||
}}>
|
||||
<Picker
|
||||
selectedValue={state.selectedCity?.id}
|
||||
onValueChange={(value, event) => dispatch(selectCity({cityId: value}))}
|
||||
>
|
||||
{state.cities.map(city => (
|
||||
<Picker.Item
|
||||
key={city.id}
|
||||
label={city.name}
|
||||
value={city.id}
|
||||
style={{fontSize: responsiveWidth(3)}}
|
||||
/>
|
||||
))}
|
||||
</Picker>
|
||||
</View>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
export default CitySelect;
|
||||
@@ -13,11 +13,12 @@ import DateTimePicker from '@react-native-community/datetimepicker';
|
||||
import {RootState} from "../../../redux/store";
|
||||
import {
|
||||
closeOrdersFilterModal,
|
||||
orderStatuses,
|
||||
orderStatuses, setCity,
|
||||
setDesc,
|
||||
setOrderBy, setShipmentDate, setShippingWarehouse, setStatus
|
||||
} from "../../../features/ordersFilter/ordersFilterSlice";
|
||||
import ShippingWarehouseSelect from "../../ShippingWarehouseSelect/ShippingWarehouseSelect";
|
||||
import CitySelect from "../../CitySelect/CitySelect";
|
||||
|
||||
export type SortingModalHandles = {
|
||||
present: () => void;
|
||||
@@ -49,6 +50,7 @@ const createRadioButton = (element: SortingModalElement) => {
|
||||
const SortingModal = () => {
|
||||
const state = useSelector((state: RootState) => state.ordersFilter);
|
||||
const shipmentWarehouseSelectorState = useSelector((state: RootState) => state.shippingWarehouseSelect);
|
||||
const citySelectorState = useSelector((state: RootState) => state.citySelect);
|
||||
|
||||
const elements = [
|
||||
{id: 'createdOnAsc', value: 'createdOnAsc', label: 'Дата создания по возрастанию'},
|
||||
@@ -77,6 +79,9 @@ const SortingModal = () => {
|
||||
useEffect(() => {
|
||||
dispatch(setShippingWarehouse(shipmentWarehouseSelectorState.selectedShippingWarehouse));
|
||||
}, [shipmentWarehouseSelectorState.selectedShippingWarehouse]);
|
||||
useEffect(() => {
|
||||
dispatch(setCity(citySelectorState.selectedCity));
|
||||
}, [citySelectorState.selectedCity]);
|
||||
return (
|
||||
<BottomSheetModal
|
||||
ref={modalRef}
|
||||
@@ -104,37 +109,38 @@ const SortingModal = () => {
|
||||
|
||||
|
||||
<View style={styles.selectors}>
|
||||
<View style={styles.selector}>
|
||||
<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>
|
||||
{/*<View style={styles.selector}>*/}
|
||||
{/* <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>*/}
|
||||
|
||||
<ShippingWarehouseSelect/>
|
||||
<CitySelect/>
|
||||
</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()));
|
||||
}
|
||||
}}/>}
|
||||
{/*<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>
|
||||
|
||||
|
||||
|
||||
@@ -43,10 +43,11 @@ const OrderCard: FC<Props> = ({onPress, onSelect, order}) => {
|
||||
<DText>Создан: {order.createdOn}</DText>
|
||||
<DText>Отгрузка: {order.shipmentDate}</DText>
|
||||
<DText>Склад отгрузки: {order.shippingWarehouse}</DText>
|
||||
<DText>Город: {order.city}</DText>
|
||||
|
||||
</View>
|
||||
<View style={styles.descriptionStatus}>
|
||||
<DText style={order.status >= OrderStatus.CANCELLED && {color: "red"}}>
|
||||
<DText style={order.status >= OrderStatus.CANCELLED && {color: "red"}}>
|
||||
{OrderStatusDictionary[order.status as OrderStatus]}
|
||||
</DText>
|
||||
</View>
|
||||
|
||||
36
src/features/citySelect/citySelectSlice.ts
Normal file
36
src/features/citySelect/citySelectSlice.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import {City, noCity} from "../../types/city";
|
||||
import {createSlice, PayloadAction} from "@reduxjs/toolkit";
|
||||
|
||||
export interface CitySelectState {
|
||||
cities: City[];
|
||||
selectedCity: City;
|
||||
initialized: boolean;
|
||||
}
|
||||
|
||||
const initialState: CitySelectState = {
|
||||
cities: [],
|
||||
selectedCity: noCity,
|
||||
initialized: false
|
||||
}
|
||||
|
||||
|
||||
export const citySelect = createSlice({
|
||||
name: 'citySelect',
|
||||
initialState,
|
||||
reducers: {
|
||||
initializeCitySelect: (state, action: PayloadAction<City[]>) => {
|
||||
state.cities = action.payload;
|
||||
state.initialized = true;
|
||||
if (state.cities.length > 0) state.selectedCity = state.cities[0];
|
||||
},
|
||||
selectCity: (state, action: PayloadAction<{ cityId: number }>) => {
|
||||
let selectedCity = state.cities.find(city => city.id == action.payload.cityId);
|
||||
if (!selectedCity) return;
|
||||
state.selectedCity = selectedCity;
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
export const {initializeCitySelect, selectCity} = citySelect.actions;
|
||||
export default citySelect.reducer;
|
||||
@@ -1,6 +1,7 @@
|
||||
import {createSlice, PayloadAction} from "@reduxjs/toolkit";
|
||||
import {ShippingWarehouse} from "../../types/shippingWarehouse";
|
||||
import {noShippingWarehouse, ShippingWarehouse} from "../../types/shippingWarehouse";
|
||||
import ShippingWarehouseSelect from "../../components/ShippingWarehouseSelect/ShippingWarehouseSelect";
|
||||
import {City, noCity} from "../../types/city";
|
||||
|
||||
export enum OrderStatus {
|
||||
ALL = -1,
|
||||
@@ -44,7 +45,8 @@ export interface OrdersFilterState {
|
||||
status: OrderStatus;
|
||||
shipmentDate: string;
|
||||
page: number;
|
||||
shippingWarehouse: ShippingWarehouse
|
||||
shippingWarehouse: ShippingWarehouse;
|
||||
city: City;
|
||||
}
|
||||
|
||||
const initialState: OrdersFilterState = {
|
||||
@@ -54,10 +56,8 @@ const initialState: OrdersFilterState = {
|
||||
shipmentDate: (new Date()).toISOString(),
|
||||
status: OrderStatus.AWAITING_PACKAGING,
|
||||
page: 0,
|
||||
shippingWarehouse: {
|
||||
id: -1,
|
||||
name: 'Все склады отгрузки'
|
||||
}
|
||||
shippingWarehouse: noShippingWarehouse,
|
||||
city: noCity
|
||||
}
|
||||
|
||||
export const ordersFilterSlice = createSlice({
|
||||
@@ -85,6 +85,9 @@ export const ordersFilterSlice = createSlice({
|
||||
setShippingWarehouse: (state, action: PayloadAction<ShippingWarehouse>) => {
|
||||
state.shippingWarehouse = action.payload;
|
||||
},
|
||||
setCity: (state, action: PayloadAction<City>) => {
|
||||
state.city = action.payload;
|
||||
},
|
||||
setPage: (state, action: PayloadAction<number>) => {
|
||||
console.log(action)
|
||||
state.page = action.payload;
|
||||
@@ -107,6 +110,7 @@ export const {
|
||||
setDesc,
|
||||
setStatus,
|
||||
setShipmentDate,
|
||||
setCity,
|
||||
setPage,
|
||||
setShippingWarehouse
|
||||
} = ordersFilterSlice.actions;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {createSlice, PayloadAction} from "@reduxjs/toolkit";
|
||||
import {ShippingWarehouse} from "../../types/shippingWarehouse";
|
||||
import {noShippingWarehouse, ShippingWarehouse} from "../../types/shippingWarehouse";
|
||||
|
||||
export interface ShippingWarehouseSelectState {
|
||||
shippingWarehouses: ShippingWarehouse[]
|
||||
@@ -9,10 +9,7 @@ export interface ShippingWarehouseSelectState {
|
||||
|
||||
const initialState: ShippingWarehouseSelectState = {
|
||||
shippingWarehouses: [],
|
||||
selectedShippingWarehouse: {
|
||||
id: -1,
|
||||
name: "Все склады отгрузки"
|
||||
},
|
||||
selectedShippingWarehouse: noShippingWarehouse,
|
||||
initialized: false
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import printingReducer from 'features/printing/printingSlice';
|
||||
import reprintModalReducer from 'features/reprintModal/reprintModalSlice';
|
||||
import ordersFilterReducer from 'features/ordersFilter/ordersFilterSlice';
|
||||
import shippingWarehouseSelectReducer from 'features/shippingWarehouseSelect/shippingWarehouseSelectSlice';
|
||||
import citySelectReducer from 'features/citySelect/citySelectSlice';
|
||||
import {useDispatch} from "react-redux";
|
||||
|
||||
export const store = configureStore({
|
||||
@@ -23,7 +24,8 @@ export const store = configureStore({
|
||||
reprintModal: reprintModalReducer,
|
||||
imageZoomModal: imageZoomModalReducer,
|
||||
ordersFilter: ordersFilterReducer,
|
||||
shippingWarehouseSelect: shippingWarehouseSelectReducer
|
||||
shippingWarehouseSelect: shippingWarehouseSelectReducer,
|
||||
citySelect: citySelectReducer
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -19,10 +19,11 @@ const useBarcodeOrders = (props: Props) => {
|
||||
desc,
|
||||
shipmentDate,
|
||||
status,
|
||||
shippingWarehouse
|
||||
shippingWarehouse,
|
||||
city
|
||||
} = useSelector((state: RootState) => state.ordersFilter);
|
||||
const fetchOrders = async (): Promise<Order[]> => {
|
||||
return ordersApi.getOrdersByProduct({productId, orderBy, shipmentDate, status, shippingWarehouse, desc});
|
||||
return ordersApi.getOrdersByProduct({productId, orderBy, shipmentDate, status, shippingWarehouse,city, desc});
|
||||
}
|
||||
useEffect(() => {
|
||||
if (isVisible || productId < 0) return;
|
||||
|
||||
@@ -64,6 +64,7 @@ function CommonPage() {
|
||||
|
||||
const checkUpdates = async () => {
|
||||
const currentVersion = Constants.manifest2?.extra?.expoClient?.version || Constants.manifest?.version;
|
||||
|
||||
applicationApi.getVersion('assemblr').then(({latest_version}) => {
|
||||
|
||||
if (currentVersion == latest_version) return;
|
||||
|
||||
@@ -244,6 +244,7 @@ const OrderScreen: FC<OrderScreenProps> = ({order}) => {
|
||||
<DText>Отгрузка: {order.shipmentDate}</DText>
|
||||
<DText>Статус: {OrderStatusDictionary[order.status as OrderStatus]}</DText>
|
||||
<DText>Склад отгрузки: {order.shippingWarehouse}</DText>
|
||||
<DText>Город: {order.city}</DText>
|
||||
<DText>{}</DText>
|
||||
<DTitle style={styles.contentTitle}>Товар</DTitle>
|
||||
<DText>Арт. DENCO: {selectedProduct?.dencoArticle}</DText>
|
||||
|
||||
9
src/types/city.ts
Normal file
9
src/types/city.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type City = {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const noCity = {
|
||||
id: -1,
|
||||
name: "Все города"
|
||||
}
|
||||
@@ -27,5 +27,6 @@ export type Order = {
|
||||
shipmentDate: string;
|
||||
createdOn: string;
|
||||
shippingWarehouse: string;
|
||||
city: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
export type ShippingWarehouse = {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const noShippingWarehouse = {
|
||||
id: -1,
|
||||
name: "Все склады отгрузки"
|
||||
}
|
||||
Reference in New Issue
Block a user