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