Skip to content

Commit

Permalink
Merge pull request #572 from ninjas-code-official/fix/issues-by-client
Browse files Browse the repository at this point in the history
fix issues pointed by client
  • Loading branch information
charles-aric authored Jun 7, 2024
2 parents 0b3bc8e + 76020ee commit b9cfcf0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 82 deletions.
6 changes: 2 additions & 4 deletions enatega-multivendor-app/src/components/CartItem/CartItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useTranslation } from 'react-i18next'
import { IMAGE_LINK } from '../../utils/constants'

const CartItem = props => {
const cartRestaurant = props.cartRestaurant
const { t } = useTranslation()
const configuration = useContext(ConfigurationContext)
const themeContext = useContext(ThemeContext)
Expand All @@ -26,9 +27,6 @@ const CartItem = props => {
setIsDropdownOpen(!isDropdownOpen)
}
const navigation = useNavigation()
const navigateBack = () => {
navigation.goBack() // Navigate back function
}

return (
<View style={styles().itemContainer}>
Expand Down Expand Up @@ -109,7 +107,7 @@ const CartItem = props => {
{parseFloat(props.dealPrice).toFixed(2)}
</TextDefault>
<View style={styles().divider} />
<TouchableOpacity onPress={navigateBack}>
<TouchableOpacity onPress={() => navigation.navigate('Restaurant', { _id: cartRestaurant })}>
<TextDefault
textColor={currentTheme.fontFourthColor}
bolder
Expand Down
1 change: 1 addition & 0 deletions enatega-multivendor-app/src/screens/Cart/Cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ function Cart(props) {
optionsTitle={food.optionsTitle}
itemImage={food.image}
itemAddons={food.addons}
cartRestaurant= {cartRestaurant}
dealPrice={(
parseFloat(food.price) * food.quantity
).toFixed(2)}
Expand Down
132 changes: 67 additions & 65 deletions enatega-multivendor-app/src/screens/Cart/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,81 @@ import { MaterialIcons } from '@expo/vector-icons'
import { useNavigation } from '@react-navigation/native'
import ConfigurationContext from '../../context/Configuration'
import { useTranslation } from 'react-i18next'
import { IMAGE_LINK } from '../../utils/constants'

const RELATED_ITEMS = gql`${relatedItemsQuery}`
const RESTAURANT = gql`${restaurantQuery}`
const FOOD = gql`${food}`
const Section = ({ itemId, restaurantId }) => {
const { t } = useTranslation()
const navigation = useNavigation()
const client = useApolloClient()
const themeContext = useContext(ThemeContext)
const configuration = useContext(ConfigurationContext)
const currentTheme = theme[themeContext.ThemeValue]
const { loading, error, data } = useQuery(RELATED_ITEMS, { variables: { itemId, restaurantId } })
if (loading) return <View />
if (error) return <View />
const { relatedItems } = data
if (relatedItems.length < 1) return <View />
const result = client.readQuery({ query: RESTAURANT, variables: { id: restaurantId } })
const slicedItems = relatedItems.length > 3 ? relatedItems.slice(0, 3) : relatedItems
const restaurant = result?.restaurant
const renderItem = ({ item }) => {
const food = client.readFragment({ id: `Food:${item}`, fragment: FOOD })
const onAdd = () => {
navigation.push('ItemDetail', {
food: {
...food,
restaurantName: restaurant.name
},
addons: restaurant.addons,
options: restaurant.options,
restaurant: restaurant._id
})
const { t } = useTranslation()
const navigation = useNavigation()
const client = useApolloClient()
const themeContext = useContext(ThemeContext)
const configuration = useContext(ConfigurationContext)
const currentTheme = theme[themeContext.ThemeValue]
const { loading, error, data } = useQuery(RELATED_ITEMS, { variables: { itemId, restaurantId } })
if (loading) return <View />
if (error) return <View />
const { relatedItems } = data
if (relatedItems.length < 1) return <View />
const result = client.readQuery({ query: RESTAURANT, variables: { id: restaurantId } })
const slicedItems = relatedItems.length > 3 ? relatedItems.slice(0, 3) : relatedItems
const restaurant = result?.restaurant
const renderItem = ({ item }) => {
const food = client.readFragment({ id: `Food:${item}`, fragment: FOOD })
const imageUrl = food.image && food.image.trim() !== '' ? food.image : IMAGE_LINK;
const onAdd = () => {
navigation.push('ItemDetail', {
food: {
...food,
restaurantName: restaurant.name
},
addons: restaurant.addons,
options: restaurant.options,
restaurant: restaurant._id
})
}
return <View style={{ ...alignment.PRsmall }}>
<View style={styles().suggestItemContainer}>
{imageUrl &&
<View style={styles().suggestItemImgContainer}>
<Image
source={{ uri: imageUrl }}
style={styles().suggestItemImg}
resizeMode="contain"
/>
</View>
}
return <View style={{ ...alignment.PRsmall }}>
<View style={styles().suggestItemContainer}>
{food.image &&
<View style={styles().suggestItemImgContainer}>
<Image
source={{ uri: food.image }}
style={styles().suggestItemImg}
resizeMode="contain"
/>
</View>
}
<TextDefault
numberOfLines={1}
style={styles().suggestItemName}
textColor={currentTheme.fontFourthColor}
H5
bolder>
{food.title}
</TextDefault>
<View
style={{
flexDirection: 'row',
alignItems: 'flex-start',
justifyContent: 'space-between'
}}>
<TextDefault
style={styles().suggestItemPrice}
textColor={currentTheme.fontFourthColor}
normal
bolder>
{`${configuration.currencySymbol}${food.variations[0].price}`}
</TextDefault>
<TouchableOpacity onPress={onAdd}>
<View style={styles(currentTheme).addToCart}>
<MaterialIcons name="add" size={scale(20)} color={currentTheme.themeBackground} />
</View>
</TouchableOpacity>
</View>
<TextDefault
numberOfLines={1}
style={styles().suggestItemName}
textColor={currentTheme.fontFourthColor}
H5
bolder>
{food.title}
</TextDefault>
<View
style={{
flexDirection: 'row',
alignItems: 'flex-start',
justifyContent: 'space-between'
}}>
<TextDefault
style={styles().suggestItemPrice}
textColor={currentTheme.fontFourthColor}
normal
bolder>
{`${configuration.currencySymbol}${food.variations[0].price}`}
</TextDefault>
<TouchableOpacity onPress={onAdd}>
<View style={styles(currentTheme).addToCart}>
<MaterialIcons name="add" size={scale(20)} color={currentTheme.themeBackground} />
</View>
</TouchableOpacity>
</View>
}
</View>
</View>
}


return (
Expand Down
4 changes: 0 additions & 4 deletions enatega-multivendor-app/src/screens/Cart/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ const styles = (props = null) =>
...alignment.PLsmall,
...alignment.PRsmall
},
imageContainer: {
alignItems: 'center',
flexDirection: 'row'
},
cartInnerContainer: {
...alignment.MTxSmall
},
Expand Down
18 changes: 9 additions & 9 deletions enatega-multivendor-app/src/screens/Restaurant/Restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,14 @@ function Restaurant(props) {
iconRadius={iconRadius}
iconTouchWidth={iconTouchWidth}
iconTouchHeight={iconTouchHeight}
restaurantName={propsData.name}
restaurantName={propsData?.name ?? data?.restaurant?.name}
restaurantId={propsData._id}
restaurantImage={propsData.image}
restaurantImage={propsData?.image ?? data?.restaurant?.image}
restaurant={null}
topaBarData={[]}
loading={loading}
minimumOrder={propsData.minimumOrder}
tax={propsData.tax}
minimumOrder={propsData?.minimumOrder ?? data?.restaurant?.minimumOrder}
tax={propsData?.tax ?? data?.restaurant?.tax}
updatedDeals={[]}
searchOpen={searchOpen}
showSearchResults={showSearchResults}
Expand Down Expand Up @@ -571,15 +571,15 @@ function Restaurant(props) {
iconRadius={iconRadius}
iconTouchWidth={iconTouchWidth}
iconTouchHeight={iconTouchHeight}
restaurantName={propsData.name}
restaurantName={propsData?.name ?? data?.restaurant?.name}
restaurantId={propsData._id}
restaurantImage={propsData.image}
restaurant={data.restaurant}
restaurantImage={propsData?.image ?? data?.restaurant?.image}
restaurant={data?.restaurant}
topaBarData={updatedDeals}
changeIndex={changeIndex}
selectedLabel={selectedLabel}
minimumOrder={propsData.minimumOrder}
tax={propsData.tax}
minimumOrder={propsData?.minimumOrder ?? data?.restaurant?.minimumOrder}
tax={propsData?.tax ?? data?.restaurant?.tax}
updatedDeals={updatedDeals}
searchOpen={searchOpen}
showSearchResults={showSearchResults}
Expand Down

0 comments on commit b9cfcf0

Please sign in to comment.