Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions src/components/ProductDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { createContext, useContext } from 'react';
import { View } from 'react-native';
import { TouchableOpacity, View } from 'react-native';
import { Chip, Divider, Caption as PaperCaption, Title as PaperTitle, Text } from 'react-native-paper';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';

import { HYPHEN } from '../../constants';
import Product from '../../data/product/Product';
Expand All @@ -10,6 +11,9 @@ export type ProductDetailsItem = {
icon?: string;
label: string;
value: string | number | null;
secondaryValue?: string | null;
onPress?: () => void;
accessibilityLabel?: string;
};

type ProductContextType = {
Expand Down Expand Up @@ -85,20 +89,45 @@ function List({ items }: { items: ProductDetailsItem[] }) {
return (
<View>
{items.map((item) => (
<Item key={item.label} icon={item.icon} label={item.label} value={item.value} />
<Item key={item.label} {...item} />
))}
</View>
);
}

function Item({ icon, label, value }: ProductDetailsItem) {
return (
<Chip icon={icon} style={[styles.chipDefault, styles.marginTopSmall]}>
<Text style={styles.chipText}>
{label}: <Text style={[styles.chipText, styles.fontBold]}>{value ?? HYPHEN}</Text>
</Text>
</Chip>
function Item({ icon, label, value, secondaryValue, onPress, accessibilityLabel }: ProductDetailsItem) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the purpose of that component is, but I would expect Item to be able to receive a child component and render it, so that the content can be a separate component and passed as a prop. But I may not be right in your case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, and I agree making it composable is the right path. Nevertheless, this ProductDetails.Item is used across multiple screens, so the refactor would broaden this ticket's scope. We can create a separate ticket for it and keep it outside OBLS-932.

const content = (
<View>
<Chip
icon={icon}
style={[styles.chipDefault, styles.marginTopSmall]}
textStyle={onPress ? styles.pressableChipText : undefined}
>
<Text style={styles.chipText}>
{label}: <Text style={[styles.chipText, styles.fontBold]}>{value ?? HYPHEN}</Text>
{secondaryValue ? (
<Text style={[styles.chipText, styles.secondaryValue]}>{`, ${secondaryValue}`}</Text>
) : null}
</Text>
</Chip>
{onPress ? <Icon name="chevron-right" size={20} style={styles.itemChevron} /> : null}
</View>
);

if (onPress) {
return (
<TouchableOpacity
activeOpacity={0.7}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
onPress={onPress}
>
{content}
</TouchableOpacity>
);
}

return content;
}

function Separator() {
Expand Down
12 changes: 12 additions & 0 deletions src/components/ProductDetails/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ export default StyleSheet.create({
borderRadius: 4,
alignItems: 'center'
},
pressableChipText: {
paddingRight: 24
},
chipText: {
fontSize: 12,
color: Theme.colors.text
},
itemChevron: {
position: 'absolute',
right: Theme.spacing.small,
top: 12,
color: Theme.colors.secondaryForeground
},
fontBold: {
fontWeight: 'bold'
},
secondaryValue: {
color: Theme.colors.secondaryForeground
},
title: {
fontSize: 18,
color: Theme.colors.text,
Expand Down
87 changes: 87 additions & 0 deletions src/screens/Picking/CustomerDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';
import { Modal, TouchableOpacity, View } from 'react-native';
import { Divider, Text } from 'react-native-paper';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';

import { ProductDetails } from '../../components/ProductDetails';
import { HYPHEN } from '../../constants';
import { DestinationAddress } from '../../types/picking';
import styles from './customerDetailsStyles';
Comment on lines +6 to +9

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you guys have a ticket for fixing the imports? I mean using aliases here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, as far as I'm aware. We talked about it several times, but no action items were created.


type CustomerDetailsProps = {
name?: string;
address?: DestinationAddress | null;
};

function compact(parts: Array<string | null | undefined>) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use arrow functions?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with useState, no technical requirement behind it and there is no "team convention", so we just use both declarations.

return parts.filter(Boolean).join(', ');
}

function AddressDetails({ address }: { address?: DestinationAddress | null }) {
const addressLine1 = address?.address || HYPHEN;
const locality = compact([address?.city, address?.stateOrProvince, address?.postalCode]);
const hasAddress = Boolean(
address?.address || address?.address2 || locality || address?.country || address?.description
);

return (
<>
<Text style={styles.addressLine}>{addressLine1}</Text>
{address?.address2 ? <Text style={styles.addressLine}>{address.address2}</Text> : null}
{locality ? <Text style={styles.addressLine}>{locality}</Text> : null}
{address?.country ? <Text style={styles.addressLine}>{address.country}</Text> : null}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll ask Emilia if the country is really necessary

{address?.description ? <Text style={styles.description}>{address.description}</Text> : null}
{!hasAddress ? (
<Text style={styles.missingAddress}>No delivery address is available in customer master data.</Text>
) : null}
</>
);
}

export function CustomerDetails({ name, address }: CustomerDetailsProps) {
const [visible, setVisible] = React.useState(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for using useState called on a React object rather than importing the useState directly?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No functional reason here. Just used it like that because the picking files follow this pattern.


return (
<>
<ProductDetails.Item
icon="map-marker"
label="Customer"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use here destinationLocationType from currentTask not to limit ourselves that it will always be Customer. I would use { destinationLocationType || 'Customer' }

value={name || HYPHEN}
secondaryValue={address?.address}
accessibilityLabel={`View delivery address for ${name || 'customer'}`}
onPress={() => setVisible(true)}
/>

<Modal transparent visible={visible} animationType="fade" onRequestClose={() => setVisible(false)}>
<View style={styles.overlay}>
<View style={styles.dialog}>
<View style={styles.header}>
<View style={styles.headerText}>
<Text style={styles.eyebrow}>CUSTOMER</Text>

@druchniewicz druchniewicz Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use here destinationLocationType from currentTask not to limit ourselves that it will always be Customer. I would use { destinationLocationType || 'Customer' }

<Text style={styles.title}>{name || HYPHEN}</Text>
</View>
<TouchableOpacity
style={styles.closeButton}
accessibilityRole="button"
accessibilityLabel="Close customer details"
onPress={() => setVisible(false)}
>
<Icon name="close" size={20} style={styles.closeIcon} />
</TouchableOpacity>
</View>

<Divider />

<View style={styles.addressSection}>
<Icon name="map-marker-outline" size={22} style={styles.addressIcon} />
<View style={styles.addressText}>
<Text style={styles.eyebrow}>SHIP TO ADDRESS</Text>
<AddressDetails address={address} />
</View>
</View>
</View>
</View>
</Modal>
</>
);
}
13 changes: 7 additions & 6 deletions src/screens/Picking/PickingPickLocationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EMPTY_STRING, HYPHEN } from '../../constants';
import { navigate } from '../../NavigationService';
import { RootState } from '../../redux/reducers';
import { parseFromISODateToLocaleString } from '../../utils/utils';
import { CustomerDetails } from './CustomerDetails';
import { usePickingContext } from './PickingContext';
import { ReallocateModal } from './ReallocateModal';
import styles from './styles';
Expand Down Expand Up @@ -89,12 +90,12 @@ export default function PickingPickLocationScreen() {
icon: 'identifier',
label: 'Order Number',
value: currentTask.requisitionNumber || HYPHEN
},
{
icon: 'map-marker',
label: currentTask.destinationLocationType || 'Destination',
value: currentTask.destination || HYPHEN
},
}
]}
/>
<CustomerDetails name={currentTask.destination} address={currentTask.destinationAddress} />
<ProductDetails.List
items={[
{
icon: 'package',
label: 'Quantity Picked',
Expand Down
13 changes: 7 additions & 6 deletions src/screens/Picking/PickingPickOutboundContainerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EMPTY_STRING, HYPHEN } from '../../constants';
import { navigate } from '../../NavigationService';
import { ReasonCode } from '../../types/picking';
import { parseFromISODateToLocaleString } from '../../utils/utils';
import { CustomerDetails } from './CustomerDetails';
import { revalidateTaskAndProceed } from './lib';
import { usePickingContext } from './PickingContext';
import styles from './styles';
Expand Down Expand Up @@ -121,12 +122,12 @@ export default function PickingPickOutboundContainerScreen() {
icon: 'identifier',
label: 'Order Number',
value: currentTask.requisitionNumber || HYPHEN
},
{
icon: 'map-marker',
label: currentTask.destinationLocationType || 'Destination',
value: currentTask.destination || HYPHEN
},
}
]}
/>
<CustomerDetails name={currentTask.destination} address={currentTask.destinationAddress} />
<ProductDetails.List
items={[
{
icon: 'account',
label: 'Assignee',
Expand Down
13 changes: 7 additions & 6 deletions src/screens/Picking/PickingPickProductScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSearchButton } from '../../components/SearchButton/useSearchButton';
import { EMPTY_STRING, HYPHEN } from '../../constants';
import { navigate } from '../../NavigationService';
import { isProductBarcodeValid, parseFromISODateToLocaleString } from '../../utils/utils';
import { CustomerDetails } from './CustomerDetails';
import { usePickingContext } from './PickingContext';
import styles from './styles';

Expand Down Expand Up @@ -61,12 +62,12 @@ export default function PickingPickProductScreen() {
icon: 'identifier',
label: 'Order Number',
value: currentTask.requisitionNumber || HYPHEN
},
{
icon: 'map-marker',
label: currentTask.destinationLocationType || 'Destination',
value: currentTask.destination || HYPHEN
},
}
]}
/>
<CustomerDetails name={currentTask.destination} address={currentTask.destinationAddress} />
<ProductDetails.List
items={[
{
icon: 'account',
label: 'Assignee',
Expand Down
13 changes: 7 additions & 6 deletions src/screens/Picking/PickingPickQuantityScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { navigate } from '../../NavigationService';
import { getReasonCodesAction } from '../../redux/actions/others';
import { ReasonCode } from '../../types/picking';
import { parseFromISODateToLocaleString } from '../../utils/utils';
import { CustomerDetails } from './CustomerDetails';
import { proceedToNextOrComplete } from './lib';
import { usePickingContext } from './PickingContext';
import styles from './styles';
Expand Down Expand Up @@ -138,12 +139,12 @@ export default function PickingPickQuantityScreen() {
icon: 'identifier',
label: 'Order Number',
value: currentTask.requisitionNumber || HYPHEN
},
{
icon: 'map-marker',
label: currentTask.destinationLocationType || 'Destination',
value: currentTask.destination || HYPHEN
},
}
]}
/>
<CustomerDetails name={currentTask.destination} address={currentTask.destinationAddress} />
<ProductDetails.List
items={[
{
icon: 'account',
label: 'Assignee',
Expand Down
13 changes: 7 additions & 6 deletions src/screens/Picking/PickingPickStagingLocationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSearchButton } from '../../components/SearchButton/useSearchButton';
import { EMPTY_STRING, HYPHEN } from '../../constants';
import { resetToRoutes } from '../../NavigationService';
import { parseFromISODateToLocaleString } from '../../utils/utils';
import { CustomerDetails } from './CustomerDetails';
import { usePickingContext } from './PickingContext';
import styles from './styles';

Expand Down Expand Up @@ -153,12 +154,12 @@ export default function PickingPickStagingLocationScreen() {
icon: 'identifier',
label: 'Order Number',
value: currentTask.requisitionNumber || HYPHEN
},
{
icon: 'map-marker',
label: currentTask.destinationLocationType || 'Destination',
value: currentTask.destination || HYPHEN
},
}
]}
/>
<CustomerDetails name={currentTask.destination} address={currentTask.destinationAddress} />
<ProductDetails.List
items={[
{
icon: 'account',
label: 'Assignee',
Expand Down
Loading