Skip to content

Commit

Permalink
list: display only cash_on_delivery; (restaurant) order details: disp…
Browse files Browse the repository at this point in the history
…lay all payment methods; (courier) task details: display only cash_on delivery; #1576 #1575
  • Loading branch information
vladimir-8 committed Oct 18, 2024
1 parent 4f8e6ed commit 1eb89a8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
22 changes: 17 additions & 5 deletions src/components/PaymentMethodInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,27 @@ export const loadDescriptionTranslationKey = paymentMethod =>
export const isKnownPaymentMethod = paymentMethod =>
Object.prototype.hasOwnProperty.call(paymentMethods, paymentMethod);

export const PaymentMethodInfo = ({ fullDetail, paymentMethod }) => {
const { t } = useTranslation();

export const isDisplayPaymentMethodInList = paymentMethod => {
if (!isKnownPaymentMethod(paymentMethod)) {
return false;
}

return paymentMethod === 'CASH_ON_DELIVERY';
};

export const PaymentMethodInList = ({ paymentMethod }) => {
if (!isDisplayPaymentMethodInList(paymentMethod)) {
return null;
}

if (!fullDetail) {
return <Icon as={Foundation} name={loadIconKey(paymentMethod)} />;
return <Icon as={Foundation} name={loadIconKey(paymentMethod)} />;
}

export const PaymentMethodInOrderDetails = ({ paymentMethod }) => {
const { t } = useTranslation();

if (!isKnownPaymentMethod(paymentMethod)) {
return null;
}

return (
Expand Down
5 changes: 2 additions & 3 deletions src/components/TaskListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
taskTypeIconName,
} from '../navigation/task/styles/common';
import { greenColor, redColor, yellowColor } from '../styles/common';
import { PaymentMethodInfo } from './PaymentMethodInfo';
import { PaymentMethodInList } from './PaymentMethodInfo';
import TaskTitle from './TaskTitle';

const styles = StyleSheet.create({
Expand Down Expand Up @@ -270,8 +270,7 @@ class TaskListItem extends Component {
<Icon mr="2" as={FontAwesome} name="comments" size="xs" />
) : null}
{task.metadata && task.metadata.payment_method && (
<PaymentMethodInfo
fullDetail={false}
<PaymentMethodInList
paymentMethod={task.metadata.payment_method}
/>
)}
Expand Down
7 changes: 2 additions & 5 deletions src/navigation/restaurant/components/OrderHeading.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FontAwesome from 'react-native-vector-icons/FontAwesome';

import material from '../../../../native-base-theme/variables/material';
import OrderFulfillmentMethodIcon from '../../../components/OrderFulfillmentMethodIcon';
import { PaymentMethodInfo } from '../../../components/PaymentMethodInfo';
import { PaymentMethodInOrderDetails } from '../../../components/PaymentMethodInfo';
import { resolveFulfillmentMethod } from '../../../utils/order';
import OrderButtons from './OrderButtons';

Expand Down Expand Up @@ -79,10 +79,7 @@ const OrderHeading = ({
</Text>
</View>
</View>
<PaymentMethodInfo
fullDetail={true}
paymentMethod={order.paymentMethod}
/>
<PaymentMethodInOrderDetails paymentMethod={order.paymentMethod} />
<View style={{ marginBottom: 15 }}>
<OrderButtons
order={order}
Expand Down
7 changes: 2 additions & 5 deletions src/navigation/restaurant/components/OrderListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Ionicons from 'react-native-vector-icons/Ionicons';
import { useDispatch, useSelector } from 'react-redux';
import OrderNumber from '../../../components/OrderNumber';
import OrderFulfillmentMethodIcon from '../../../components/OrderFulfillmentMethodIcon';
import { PaymentMethodInfo } from '../../../components/PaymentMethodInfo';
import { PaymentMethodInList } from '../../../components/PaymentMethodInfo';
import {
selectAutoAcceptOrdersEnabled,
selectIsActionable,
Expand Down Expand Up @@ -127,10 +127,7 @@ export default function OrderListItem({ order, onItemClick }) {
<OrderNumber order={order} />
</View>
<OrderFulfillmentMethodIcon order={order} small />
<PaymentMethodInfo
fullDetail={false}
paymentMethod={order.paymentMethod}
/>
<PaymentMethodInList paymentMethod={order.paymentMethod} />
{order.notes ? (
<Icon as={FontAwesome} name="comments" size="xs" />
) : null}
Expand Down
31 changes: 14 additions & 17 deletions src/navigation/task/components/Details.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';

import ItemSeparator from '../../../components/ItemSeparator';
import {
isKnownPaymentMethod,
isDisplayPaymentMethodInList,
loadDescriptionTranslationKey,
loadIconKey,
} from '../../../components/PaymentMethodInfo';
Expand Down Expand Up @@ -91,10 +91,7 @@ const Details = ({ task, t }) => {
});
}

if (
task.metadata &&
task.metadata.has_loopeat_returns
) {
if (task.metadata && task.metadata.has_loopeat_returns) {
items.push({
iconName: 'recycle',
iconType: FontAwesome5,
Expand All @@ -109,6 +106,18 @@ const Details = ({ task, t }) => {
});
}

if (
task.metadata &&
task.metadata.payment_method &&
isDisplayPaymentMethodInList(task.metadata.payment_method)
) {
items.push({
iconName: loadIconKey(task.metadata.payment_method),
iconType: Foundation,
text: t(loadDescriptionTranslationKey(task.metadata.payment_method)),
});
}

if (task.comments) {
items.push({
iconName: 'chatbubbles',
Expand Down Expand Up @@ -164,18 +173,6 @@ const Details = ({ task, t }) => {
});
}

if (
task.metadata &&
task.metadata.payment_method &&
isKnownPaymentMethod(task.metadata.payment_method)
) {
items.push({
iconName: loadIconKey(task.metadata.payment_method),
iconType: Foundation,
text: t(loadDescriptionTranslationKey(task.metadata.payment_method)),
});
}

return (
<FlatList
data={items}
Expand Down

0 comments on commit 1eb89a8

Please sign in to comment.