@riosst100/pwa-marketplace 1.1.7 → 1.1.9

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@riosst100/pwa-marketplace",
3
3
  "author": "riosst100@gmail.com",
4
- "version": "1.1.7",
4
+ "version": "1.1.9",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -9,7 +9,8 @@
9
9
  }
10
10
  },
11
11
  "dependencies": {
12
- "axios": "^1.6.5"
12
+ "axios": "^1.6.5",
13
+ "react-phone-number-input": "^3.3.9"
13
14
  },
14
15
  "license": "MIT",
15
16
  "private": false
@@ -24,6 +24,7 @@ import Region from '@magento/venia-ui/lib/components/Region';
24
24
  import Postcode from '@magento/venia-ui/lib/components/Postcode';
25
25
  import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
26
26
  import { Link } from 'react-router-dom';
27
+ import PhoneInput from '@riosst100/pwa-marketplace/src/components/PhoneInput';
27
28
 
28
29
  const BecomeSeller = props => {
29
30
  const talonProps = useBecomeSeller({
@@ -273,7 +274,7 @@ const BecomeSeller = props => {
273
274
  defaultMessage: 'Contact Number'
274
275
  })}
275
276
  >
276
- <TextInput
277
+ <PhoneInput
277
278
  id="contactNumber"
278
279
  field="seller.contact_number"
279
280
  validate={isRequired}
@@ -0,0 +1 @@
1
+ export { default } from './phoneInput';
@@ -0,0 +1,52 @@
1
+ import React, { Fragment, useState } from 'react';
2
+ import { node, shape, string } from 'prop-types';
3
+ import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
4
+
5
+ import { useStyle } from '@magento/venia-ui/lib/classify';
6
+ import { FieldIcons, Message } from '@magento/venia-ui/lib/components/Field';
7
+ import defaultClasses from './phoneInput.module.css';
8
+ import {PhoneInput as ReactPhoneInput} from 'react-phone-number-input'
9
+
10
+ const PhoneInput = props => {
11
+ const {
12
+ after,
13
+ before,
14
+ classes: propClasses,
15
+ regionError,
16
+ field,
17
+ message,
18
+ ...rest
19
+ } = props;
20
+ const fieldState = useFieldState(field);
21
+ const classes = useStyle(defaultClasses, propClasses);
22
+ var inputClass =
23
+ fieldState.error || regionError ? classes.input_error : classes.input;
24
+
25
+ const [value, setValue] = useState('');
26
+
27
+ return (
28
+ <Fragment>
29
+ <FieldIcons after={after} before={before}>
30
+ <ReactPhoneInput
31
+ international
32
+ countryCallingCodeEditable={false}
33
+ defaultCountry="ID"
34
+ value={value}
35
+ onChange={setValue}/>
36
+ </FieldIcons>
37
+ <Message fieldState={fieldState}>{message}</Message>
38
+ </Fragment>
39
+ );
40
+ };
41
+
42
+ export default PhoneInput;
43
+
44
+ PhoneInput.propTypes = {
45
+ after: node,
46
+ before: node,
47
+ classes: shape({
48
+ input: string
49
+ }),
50
+ field: string.isRequired,
51
+ message: node
52
+ };
@@ -0,0 +1,21 @@
1
+ .input {
2
+ composes: input from '@magento/venia-ui/lib/components/Field/field.module.css';
3
+
4
+ composes: disabled_text-subtle from global;
5
+ }
6
+
7
+ .input_error {
8
+ composes: input from '@magento/venia-ui/lib/components/Field/field.module.css';
9
+
10
+ composes: border-error from global;
11
+ }
12
+
13
+ .input_shimmer {
14
+ composes: h-[2.5rem] from global;
15
+ composes: m-0 from global;
16
+ composes: max-w-full from global;
17
+ composes: rounded-md from global;
18
+ composes: w-full from global;
19
+ font-size: 1rem;
20
+ padding: calc(0.375rem - 1px) calc(0.625rem - 1px);
21
+ }
@@ -1 +0,0 @@
1
- export { default } from './inputCountryCode';
@@ -1,94 +0,0 @@
1
- import React, { Fragment } from 'react';
2
- import { useIntl } from 'react-intl';
3
- import { Minus as MinusIcon, Plus as PlusIcon } from 'react-feather';
4
- import { useInputCountryCode } from '@riosst100/pwa-marketplace/src/talons/InputCountryCode/useInputCountryCode';
5
-
6
- import { useStyle } from '../../classify';
7
- import Icon from '../Icon';
8
- import TextInput from '../TextInput';
9
- import { Message } from '../Field';
10
- import defaultClasses from './inputCountryCode.module.css';
11
-
12
- const InputCountryCode = props => {
13
- const { initialValue, itemId, label, min, onChange, message } = props;
14
- const { formatMessage } = useIntl();
15
- const classes = useStyle(defaultClasses, props.classes);
16
- const iconClasses = { root: classes.icon };
17
-
18
- const talonProps = useInputCountryCode({
19
- initialValue,
20
- min,
21
- onChange
22
- });
23
-
24
- const {
25
- isDecrementDisabled,
26
- isIncrementDisabled,
27
- handleBlur,
28
- handleDecrement,
29
- handleIncrement,
30
- maskInput
31
- } = talonProps;
32
-
33
- const errorMessage = message ? <Message>{message}</Message> : null;
34
-
35
- return (
36
- <Fragment>
37
- <div className={classes.root}>
38
- <label className={classes.label} htmlFor={itemId}>
39
- {label}
40
- </label>
41
- <button
42
- aria-label={formatMessage({
43
- id: 'quantity.buttonDecrement',
44
- defaultMessage: 'Decrease Quantity'
45
- })}
46
- className={classes.button_decrement}
47
- disabled={isDecrementDisabled}
48
- onClick={handleDecrement}
49
- type="button"
50
- data-cy="Quantity-decrementButton"
51
- >
52
- <Icon classes={iconClasses} src={MinusIcon} size={22} />
53
- </button>
54
- <TextInput
55
- aria-label={formatMessage({
56
- id: 'quantity.input',
57
- defaultMessage: 'Item Quantity'
58
- })}
59
- data-cy="QuantityStepper-input"
60
- classes={{ input: classes.input }}
61
- field="quantity"
62
- id={itemId}
63
- inputMode="numeric"
64
- mask={maskInput}
65
- min={min}
66
- onBlur={handleBlur}
67
- pattern="[0-9]*"
68
- />
69
- <button
70
- aria-label={formatMessage({
71
- id: 'quantity.buttonIncrement',
72
- defaultMessage: 'Increase Quantity'
73
- })}
74
- className={classes.button_increment}
75
- disabled={isIncrementDisabled}
76
- onClick={handleIncrement}
77
- type="button"
78
- data-cy="Quantity-incrementButton"
79
- >
80
- <Icon classes={iconClasses} src={PlusIcon} size={20} />
81
- </button>
82
- </div>
83
- {errorMessage}
84
- </Fragment>
85
- );
86
- };
87
-
88
- InputCountryCode.defaultProps = {
89
- min: 0,
90
- initialValue: 1,
91
- onChange: () => {}
92
- };
93
-
94
- export default InputCountryCode;
@@ -1,120 +0,0 @@
1
- import { useCallback, useMemo, useState, useEffect } from 'react';
2
- import { useFieldApi } from 'informed';
3
- import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
4
- import debounce from 'lodash.debounce';
5
-
6
- /**
7
- * This talon contains logic for a product quantity UI component.
8
- * It performs effects and returns prop data for rendering a component that lets you
9
- * modify the quantity of a cart item.
10
- *
11
- * This talon performs the following effects:
12
- *
13
- * - Updates the state of the quantity field when the initial value changes
14
- *
15
- * @function
16
- *
17
- * @param {Object} props
18
- * @param {number} props.initialValue the initial quantity value
19
- * @param {number} props.min the minimum allowed quantity value
20
- * @param {function} props.onChange change handler to invoke when quantity value changes
21
- *
22
- * @returns {QuantityTalonProps}
23
- *
24
- */
25
- export const useInputCountryCode = props => {
26
- const { initialValue, min, onChange } = props;
27
-
28
- const [prevQuantity, setPrevQuantity] = useState(initialValue);
29
-
30
- const quantityFieldApi = useFieldApi('quantity');
31
- const { value: quantity } = useFieldState('quantity');
32
-
33
- const isIncrementDisabled = useMemo(() => !quantity, [quantity]);
34
-
35
- // "min: 0" lets a user delete the value and enter a new one, but "1" is
36
- // actually the minimum value we allow to be set through decrement button.
37
- const isDecrementDisabled = useMemo(() => !quantity || quantity <= 1, [
38
- quantity
39
- ]);
40
-
41
- // Fire the onChange after some wait time. We calculate the current delay
42
- // as enough time for a user to spam inc/dec quantity but not enough time
43
- // for a user to click inc/dec on Product A and then click Product B.
44
- const debouncedOnChange = useMemo(
45
- () =>
46
- debounce(val => {
47
- setPrevQuantity(val);
48
- onChange(val);
49
- }, 350),
50
- [onChange]
51
- );
52
-
53
- const handleDecrement = useCallback(() => {
54
- const newQuantity = quantity - 1;
55
- quantityFieldApi.setValue(newQuantity);
56
- debouncedOnChange(newQuantity);
57
- }, [debouncedOnChange, quantity, quantityFieldApi]);
58
-
59
- const handleIncrement = useCallback(() => {
60
- const newQuantity = quantity + 1;
61
- quantityFieldApi.setValue(newQuantity);
62
- debouncedOnChange(newQuantity);
63
- }, [debouncedOnChange, quantity, quantityFieldApi]);
64
-
65
- const handleBlur = useCallback(() => {
66
- // Only submit the value change if it has changed.
67
- if (typeof quantity === 'number' && quantity != prevQuantity) {
68
- debouncedOnChange(quantity);
69
- }
70
- }, [debouncedOnChange, prevQuantity, quantity]);
71
-
72
- const maskInput = useCallback(
73
- value => {
74
- try {
75
- // For some storefronts decimal values are allowed.
76
- const nextVal = parseFloat(value);
77
- if (value && isNaN(nextVal))
78
- throw new Error(`${value} is not a number.`);
79
- if (nextVal < min) return min;
80
- else return nextVal;
81
- } catch (err) {
82
- console.error(err);
83
- return prevQuantity;
84
- }
85
- },
86
- [min, prevQuantity]
87
- );
88
-
89
- /**
90
- * Everytime initialValue changes, update the quantity field state.
91
- */
92
- useEffect(() => {
93
- quantityFieldApi.setValue(initialValue);
94
- }, [initialValue, quantityFieldApi]);
95
-
96
- return {
97
- isDecrementDisabled,
98
- isIncrementDisabled,
99
- handleBlur,
100
- handleDecrement,
101
- handleIncrement,
102
- maskInput
103
- };
104
- };
105
-
106
- /** JSDoc type definitions */
107
-
108
- /**
109
- * Object type returned by the {@link useInputCountryCode} talon.
110
- * It provides props data for a quantity UI component.
111
- *
112
- * @typedef {Object} QuantityTalonProps
113
- *
114
- * @property {boolean} isDecrementDisabled True if decrementing should be disabled
115
- * @property {boolean} isIncrementDisabled True if incrementing should be disabled
116
- * @property {function} handleBlur Callback function for handling a blur event on a component
117
- * @property {function} handleDecrement Callback function for handling a quantity decrement event
118
- * @property {function} handleIncrement Callback function for handling an increment event
119
- * @property {function} maskInput Function for masking a value when decimal values are allowed
120
- */