Skip to content

Commit

Permalink
Fix checkout page pincode bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RookieProgrammerSachin committed Oct 31, 2023
1 parent 80c26b3 commit ad26424
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pages/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default function Checkout() {
setShippingCharges(-100);
}
setValidPincode(false);
setSpinner(false);
if (err.response.status === 409) {
setVisible(true);
}
Expand All @@ -118,9 +119,10 @@ export default function Checkout() {

const handleChange = (event) => {
const text = event.target.value;
const pincodeRegex = /^[1-9][0-9]{5}$/;
setPincode((oldText) => {
setTimeout(() => {
if (text.length === 6) {
if (pincodeRegex.test(text.trim())) {
getShippingCharges(text);
} else {
setError(true);
Expand Down Expand Up @@ -202,7 +204,8 @@ export default function Checkout() {
}, []);

useEffect(() => {
if (pincode.length === 6) {
const pincodeRegex = /^[1-9][0-9]{5}$/;
if (pincodeRegex.test(pincode)) {
axios
.get(
`https://api.opencagedata.com/geocode/v1/json?key=518b0ac375bb4bb8bb17019ae3e63818&q=${pincode}`
Expand Down

0 comments on commit ad26424

Please sign in to comment.