From 1d068c5d245867bba612d16aa052d8f503c173b8 Mon Sep 17 00:00:00 2001 From: Bratu Sebastian Date: Fri, 17 Nov 2023 06:30:41 +0200 Subject: [PATCH] fix editing patient --- components/atoms/Stepper/Forms/identity2.js | 8 +++++++- lib/helper.js | 2 +- pages/voucher/buy.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/atoms/Stepper/Forms/identity2.js b/components/atoms/Stepper/Forms/identity2.js index 21d4b7c..61933fd 100644 --- a/components/atoms/Stepper/Forms/identity2.js +++ b/components/atoms/Stepper/Forms/identity2.js @@ -31,6 +31,8 @@ import CountrySelect from '../../Input/Country'; export const CountryContext = createContext(); function Identity2() { + const ls = localStorage.getItem('dispatchBuyVoucher'); + const { activeStepIndex, setActiveStepIndex, formData, setFormData } = useContext(FormContext); const [phone, setPhone] = useState(); @@ -41,7 +43,7 @@ function Identity2() { const dispatch = useDispatch(); const [state, setState] = useState({ type: 0, message: '' }); const client = useSelector((state) => state.app.client); - const [newBenecifiare, setNewBenecifiare] = useState(false); + const [newBenecifiare, setNewBenecifiare] = useState( ls && JSON.parse(ls).id? true : false ); const [activeIndexSlide, setActiveIndexSlide] = useState(null); const [country, setCountry] = useState('cd'); const [countryLabel, setCountryLabel] = useState('RD Congo'); @@ -102,6 +104,10 @@ function Identity2() { ); setActiveStepIndex(activeStepIndex + 1); } else { + const ls = JSON.parse( localStorage.getItem('dispatchBuyVoucher') ); + if( ls && ls.id ){ + data.id = ls.id; + } savePatientMutation.mutate({ ...data, accessToken: session.accessToken }); } }; diff --git a/lib/helper.js b/lib/helper.js index 2690f75..3b7364b 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -116,7 +116,7 @@ export async function savePatient(formData) { delete formData.accessToken; const Options = { - method: 'POST', + method: formData?.id? 'PUT' : 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, diff --git a/pages/voucher/buy.js b/pages/voucher/buy.js index c1d3cdf..93cb812 100644 --- a/pages/voucher/buy.js +++ b/pages/voucher/buy.js @@ -14,7 +14,7 @@ const Page = () => { step == 'end' && redirect_status == 'succeeded' ? 2 : step == '1' ? 1 : 0, ); const [formData, setFormData] = useState({}); - const [kycTest, setKycTest] = useState(true); + const [kycTest, setKycTest] = useState(false); return ( <>