| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import React, {useEffect, useState} from "react";
- import {InputText} from "primereact/inputtext";
- import {Button} from "primereact/button";
- import {SPRING_SERVER} from "../config";
- export default function (props) {
- const userDataUrl = SPRING_SERVER + '/api/users/' + props.username;
- const [name,setName] = useState("");
- const [address, setAddress] = useState("");
- function addNewParcel() {
- fetch(userDataUrl, {
- method: 'PUT',
- headers: {
- "Authorization": "Bearer " + localStorage.getItem("access_token"),
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- deliveryAddress: address,
- recipientName: "Adam Nowak",
- deliveryTime: [
- 2024,
- 1,
- 25,
- 21,
- 34,
- 55
- ],
- packets: [
- {
- description: "Packet description",
- name: name
- }
- ]
- })
- })
- .then(response => response.json())
- .then(data => {
- props.callback()
- })
- }
- return (
- <div className="w-11 my-2 p-2 surface-200 border-round shadow-3 flex flex-column">
- <div>
- <div>Parcel name:</div>
- <InputText type="text" className="w-full p-inputtext-sm surface-300 mt-1" onChange={(e) => setName(e.target.value)}/>
- </div>
- <div className="mt-3">
- <div>Address:</div>
- <InputText type="text" className="w-full p-inputtext-sm surface-300 mt-1" onChange={(e) => setAddress(e.target.value)}/>
- </div>
- <Button onClick={() => {
- addNewParcel()
- }} className="align-self-end mt-2"><i
- className="pi pi-check text-green-500 text-xl font-bold"></i> Add</Button>
- </div>
- )
- }
|