parent
765bb5edc0
commit
980cb1ab53
@ -7,7 +7,7 @@ import { Form } from "react-bootstrap";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
export default function App() {
|
||||
const { register, handleSubmit, formState: { errors } } = useForm();
|
||||
const { register, handleSubmit, setValue, formState: { errors } } = useForm();
|
||||
const cookies = new Cookies();
|
||||
const [userAddresses, setUserAddresses] = useState([]);
|
||||
const navigate = useNavigate();
|
||||
@ -31,13 +31,13 @@ export default function App() {
|
||||
const userInfo = cookies.get("GMGM");
|
||||
if (userInfo != null && userInfo.LoggedIn == true) {
|
||||
if (userInfo.firstName != null)
|
||||
setCurrentAdress((e) => { return { ...e, firstName: userInfo.firstName } });
|
||||
setValue("firstName", userInfo.firstName);
|
||||
if (userInfo.lastName != null)
|
||||
setCurrentAdress((e) => { return { ...e, lastName: userInfo.lastName } });
|
||||
setValue("lastName", userInfo.lastName);
|
||||
if (userInfo.phone != null)
|
||||
setCurrentAdress((e) => { return { ...e, phoneNumber: userInfo.phone } });
|
||||
setValue("phoneNumber", userInfo.phone);
|
||||
if (userInfo.email != null)
|
||||
setCurrentAdress((e) => { return { ...e, emailAddress: userInfo.email } });
|
||||
setValue("emailAddress", userInfo.email);
|
||||
|
||||
fetch("https://localhost:7292/api/Address", {
|
||||
method: 'GET',
|
||||
@ -68,6 +68,14 @@ export default function App() {
|
||||
postalCode: address.postalCode
|
||||
}
|
||||
});
|
||||
|
||||
setValue("civicNumber", address.civicNumber);
|
||||
setValue("appartment", address.appartment);
|
||||
setValue("street", address.street);
|
||||
setValue("city", address.city);
|
||||
setValue("province", address.province);
|
||||
setValue("country", address.country);
|
||||
setValue("postalCode", address.postalCode);
|
||||
}
|
||||
|
||||
const onSubmit = async (data) => {
|
||||
@ -94,9 +102,7 @@ export default function App() {
|
||||
<div className="Error_color">
|
||||
<div className="form-group">
|
||||
<label>Adresse courriel*: </label>
|
||||
<input {...register("emailAddress", { required: true, pattern: /^[A-Za-z0-9+_.-]+@(.+)$/ })}
|
||||
value={currentAdress.emailAddress}
|
||||
onChange={(e) => setCurrentAdress((prev) => { return { ...prev, emailAddress: e.target.value } })} />
|
||||
<input {...register("emailAddress", { required: true, pattern: /^[A-Za-z0-9+_.-]+@(.+)$/ })}/>
|
||||
</div>
|
||||
<div>
|
||||
{errors.emailAddress && errors.emailAddress.type === 'required' && <span>Vous devez entrer une adresse courriel!</span>}
|
||||
@ -104,9 +110,7 @@ export default function App() {
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>Prénom*: </label>
|
||||
<input {...register("firstName", { required: true, minLength: 2 })}
|
||||
value={currentAdress.firstName}
|
||||
onChange={(e) => setCurrentAdress((prev) => { return { ...prev, firstName: e.target.value } })} />
|
||||
<input {...register("firstName", { required: true, minLength: 2 })}/>
|
||||
</div>
|
||||
<div>
|
||||
{errors.firstName && errors.firstName.type === 'required' && <span>Vous devez entrer votre prénom!</span>}
|
||||
@ -114,9 +118,7 @@ export default function App() {
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>Nom*: </label>
|
||||
<input {...register("lastName", { required: true, minLength: 2 })}
|
||||
value={currentAdress.lastName}
|
||||
onChange={(e) => setCurrentAdress((prev) => { return { ...prev, lastName: e.target.value } })} />
|
||||
<input {...register("lastName", { required: true, minLength: 2 })}/>
|
||||
</div>
|
||||
<div>
|
||||
{errors.lastName && errors.lastName.type === 'required' && <span>Vous devez entrer votre nom!</span>}
|
||||
@ -124,9 +126,7 @@ export default function App() {
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>Numéro de téléphone*: </label>
|
||||
<input placeholder="Exemple: 111-111-1111" {...register("phoneNumber", { required: true, pattern: /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/ })}
|
||||
value={currentAdress.phoneNumber}
|
||||
onChange={(e) => setCurrentAdress((prev) => { return { ...prev, phoneNumber: e.target.value } })} />
|
||||
<input placeholder="Exemple: 111-111-1111" {...register("phoneNumber", { required: true, pattern: /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/ })}/>
|
||||
</div>
|
||||
<div>
|
||||
{errors.phoneNumber && errors.phoneNumber.type === 'required' && <span>Vous devez entrer un numéro de téléphone!</span>}
|
||||
|
Loading…
Reference in New Issue
Block a user