From fd5ed8aa4f159c8e1c0476915432e0a97a239a91 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 1 Oct 2022 19:48:06 +0530 Subject: fixed warning 'component changing controlled input to uncontrolled' while editing shipping addresses --- src/components/editors/address-editor.js | 41 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/components/editors/address-editor.js') diff --git a/src/components/editors/address-editor.js b/src/components/editors/address-editor.js index bd81b6f..5fb8ff6 100644 --- a/src/components/editors/address-editor.js +++ b/src/components/editors/address-editor.js @@ -18,29 +18,19 @@ import { Address } from './../../classes/client'; import './scss/address-editor.scss'; +import { useState, useEffect } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faXmark } from '@fortawesome/free-solid-svg-icons'; -const AddressEditor = (props) => { - const handleInput = (field, event) => { - const a = new Address(); - const val = event.target.value; - a.Country = field === "country" ? val : props.address.Country; - a.State = field === "state" ? val : props.address.State; - a.City = field === "city" ? val : props.address.City; - a.Text = field === "address" ? val : props.address.Text; - a.PostalCode = field === "postal" ? val : props.address.PostalCode; - props.setAddress(a); - } - +const AddressEditor = ({ heading, address, setAddress, isBillingAddress, billingAddressIsShipping, setShipToBillingAddress, deleteAddress}) => { return (
-

{props.heading}

- {props.isBillingAddress || // cross button +

{heading}

+ {isBillingAddress || // cross button + onClick={deleteAddress}/> }
@@ -49,21 +39,24 @@ const AddressEditor = (props) => { Country: handleInput("country", e)} /> + value={address.Country} + onChange={(e) => setAddress({Country: e.target.value})} />
@@ -72,23 +65,25 @@ const AddressEditor = (props) => { Address: