feat: enhance AssemblyView to select product image dynamically
This commit is contained in:
@@ -10,7 +10,7 @@ import OrderInfoView from "./OrderInfoView";
|
|||||||
import AssemblyControls from "./AssemblyControls";
|
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 {selectProduct, setAssembly, startAssembly} from "../../features/assembly/assemblySlice";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
order: Order;
|
order: Order;
|
||||||
@@ -25,14 +25,23 @@ const AssemblyView = (props: Props) => {
|
|||||||
dispatch(startAssembly());
|
dispatch(startAssembly());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function getImageUrl() {
|
||||||
|
const productsImages = order.products.map(op=>op.imageUrl);
|
||||||
|
if (state.selectedProduct && productsImages.includes(state.selectedProduct.imageUrl)){
|
||||||
|
return state.selectedProduct.imageUrl;
|
||||||
|
}
|
||||||
|
if (order.products.length > 0) {
|
||||||
|
return order.products[0].imageUrl;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.viewContainer}>
|
<View style={styles.viewContainer}>
|
||||||
<View style={styles.topSection}>
|
<View style={styles.topSection}>
|
||||||
<AssemblyProductSelect order={order}/>
|
<AssemblyProductSelect order={order}/>
|
||||||
<ProductImageView
|
<ProductImageView
|
||||||
imageUrl={state.selectedProduct ? state.selectedProduct.imageUrl : order.products[0].imageUrl}/>
|
imageUrl={getImageUrl()}/>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.bottomSection}>
|
<View style={styles.bottomSection}>
|
||||||
<OrderInfoView
|
<OrderInfoView
|
||||||
|
|||||||
Reference in New Issue
Block a user