ordering-ui-react-native 0.14.28 → 0.14.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.14.28",
3
+ "version": "0.14.29",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -31,7 +31,9 @@ import {
31
31
  WrapperSubOption,
32
32
  ProductComment,
33
33
  ProductActions,
34
- ExtraOptionWrap
34
+ ExtraOptionWrap,
35
+ WeightUnitSwitch,
36
+ WeightUnitItem
35
37
  } from './styles';
36
38
  import { OButton, OIcon, OInput, OText } from '../shared';
37
39
  import { ScrollView } from 'react-native-gesture-handler';
@@ -130,6 +132,9 @@ export const ProductOptionsUI = (props: any) => {
130
132
  height: 32,
131
133
  borderRadius: 16,
132
134
  backgroundColor: 'rgba(208,208,208,0.5)'
135
+ },
136
+ unitItem: {
137
+ fontSize: 12
133
138
  }
134
139
  });
135
140
 
@@ -144,6 +149,12 @@ export const ProductOptionsUI = (props: any) => {
144
149
  const { top, bottom } = useSafeAreaInsets();
145
150
  const { height } = useWindowDimensions();
146
151
  const [selOpt, setSelectedOpt] = useState(0);
152
+ const [isHaveWeight, setIsHaveWeight] = useState(false)
153
+ const [qtyBy, setQtyBy] = useState({
154
+ weight_unit: false,
155
+ pieces: true
156
+ })
157
+ const [pricePerWeightUnit, setPricePerWeightUnit] = useState(null)
147
158
 
148
159
  const swiperRef: any = useRef(null)
149
160
 
@@ -199,6 +210,10 @@ export const ProductOptionsUI = (props: any) => {
199
210
  navigation.navigate('Login');
200
211
  };
201
212
 
213
+ const handleSwitchQtyUnit = (val: string) => {
214
+ setQtyBy({ [val]: true, [!val]: false })
215
+ }
216
+
202
217
  useEffect(() => {
203
218
  const productImgList: any = []
204
219
  product?.images && productImgList.push(product.images)
@@ -208,6 +223,11 @@ export const ProductOptionsUI = (props: any) => {
208
223
  }
209
224
  }
210
225
  setGallery(productImgList)
226
+
227
+ if (product?.weight && product?.weight_unit) {
228
+ setIsHaveWeight(true)
229
+ setPricePerWeightUnit(product?.price / product?.weight)
230
+ }
211
231
  }, [product])
212
232
 
213
233
  const saveErrors =
@@ -411,9 +431,13 @@ export const ProductOptionsUI = (props: any) => {
411
431
  }
412
432
  </OText>
413
433
  )}
414
- <OText size={16} lineHeight={24} color={theme.colors.textNormal}>
415
- {productCart.price ? parsePrice(productCart.price) : ''}
416
- </OText>
434
+ {isHaveWeight ? (
435
+ <OText size={16} lineHeight={24} color={theme.colors.textNormal}>{parsePrice(pricePerWeightUnit)} / {product?.weight_unit}</OText>
436
+ ) : (
437
+ <OText size={16} lineHeight={24} color={theme.colors.textNormal}>
438
+ {productCart.price ? parsePrice(productCart.price) : ''}
439
+ </OText>
440
+ )}
417
441
  </>
418
442
  )}
419
443
  </ProductTitle>
@@ -721,8 +745,10 @@ export const ProductOptionsUI = (props: any) => {
721
745
  <OText
722
746
  size={12}
723
747
  lineHeight={18}
724
- style={{ minWidth: 29, textAlign: 'center' }}>
725
- {productCart.quantity}
748
+ style={{ minWidth: 29, textAlign: 'center' }}
749
+ >
750
+ {qtyBy?.pieces && productCart.quantity}
751
+ {qtyBy?.weight_unit && productCart.quantity * product?.weight}
726
752
  </OText>
727
753
  <TouchableOpacity
728
754
  onPress={increment}
@@ -743,6 +769,36 @@ export const ProductOptionsUI = (props: any) => {
743
769
  }
744
770
  />
745
771
  </TouchableOpacity>
772
+ <WeightUnitSwitch>
773
+ <TouchableOpacity
774
+ onPress={() => handleSwitchQtyUnit('pieces')}
775
+ >
776
+ <WeightUnitItem active={qtyBy?.pieces}>
777
+ <OText
778
+ size={12}
779
+ lineHeight={18}
780
+ color={qtyBy?.pieces ? theme.colors.primary : theme.colors.textNormal}
781
+ >
782
+ {t('PIECES', 'pieces')}
783
+ </OText>
784
+ </WeightUnitItem>
785
+ </TouchableOpacity>
786
+ <View style={{ alignItems: 'flex-start' }}>
787
+ <TouchableOpacity
788
+ onPress={() => handleSwitchQtyUnit('weight_unit')}
789
+ >
790
+ <WeightUnitItem active={qtyBy?.weight_unit}>
791
+ <OText
792
+ size={12}
793
+ lineHeight={18}
794
+ color={qtyBy?.weight_unit ? theme.colors.primary : theme.colors.textNormal}
795
+ >
796
+ {product?.weight_unit}
797
+ </OText>
798
+ </WeightUnitItem>
799
+ </TouchableOpacity>
800
+ </View>
801
+ </WeightUnitSwitch>
746
802
  </View>
747
803
  )}
748
804
  <View
@@ -78,3 +78,15 @@ export const ProductActions = styled.View`
78
78
  export const ExtraOptionWrap = styled.ScrollView`
79
79
  margin-horizontal: -40px;
80
80
  `;
81
+
82
+ export const WeightUnitSwitch = styled.View`
83
+ margin-left: 10px;
84
+ `
85
+ export const WeightUnitItem = styled.View`
86
+ padding: 1px 5px;
87
+ border-radius: 4px;
88
+
89
+ ${({ active }: any) => active && css`
90
+ background-color: ${(props: any) => props.theme.colors.primary}20;
91
+ `}
92
+ `