1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
import React, { useState, Dispatch, SetStateAction } from "react";
import { ContractMethod, TezosToolkit, WalletContract } from "@taquito/taquito";
interface RecordsProps {
contract: WalletContract | any;
setUserBalance: Dispatch<SetStateAction<any>>;
Tezos: TezosToolkit;
userAddress: string;
setStorage: Dispatch<SetStateAction<number>>;
}
const Records = ({ contract, setUserBalance, Tezos, userAddress, setStorage }: RecordsProps) => {
const [loadingIncrement, setLoadingIncrement] = useState<boolean>(false);
const [loadingDecrement, setLoadingDecrement] = useState<boolean>(false);
const [formKaName, setName] = useState('');
const [formKaDate, setDate] = useState('');
const [formKaHeight, setHeight] = useState('');
const [formKaWeight, setWeight] = useState('');
const [formKaAge, setAge] = useState('');
const [formKaHospital, setHospital] = useState('');
const [formKaPrescription, setPrescription] = useState('');
const addRecord = async (): Promise<void> => {
setLoadingIncrement(true);
try {
const apnaForm = {
name: formKaName,
date: formKaDate,
age: formKaAge,
height: formKaHeight,
weight: formKaWeight,
hospital: formKaHospital,
prescription: formKaPrescription,
};
console.log(JSON.stringify(apnaForm));
const op = await contract.methods.default(JSON.stringify(apnaForm)).send();
await op.confirmation();
const newStorage: any = await contract.storage();
if (newStorage) setStorage(newStorage);
setUserBalance(await Tezos.tz.getBalance(userAddress));
} catch (error) {
console.log(error);
} finally {
setLoadingIncrement(false);
}
};
if (!contract && !userAddress) return <div> </div>;
return (
<div>
<form action="" method="get" className="form-apna">
<label className="labelIska">Doctor: </label>
<input type="text" className="formFields" id="form-name"
onChange={event => setName(event.target.value)} required/>
<br/>
<label className="labelIska">Date: </label>
<input type="date" className="formFields" id="form-date"
onChange={event => setDate(event.target.value)} required/><br/>
<label className="labelIska">Age: </label>
<input type="number" className="formFields" id="form-age"
onChange={event => setAge(event.target.value)} required/><br/>
<label className="labelIska">Height: </label>
<input type="number" className="formFields" id="form-height"
onChange={event => setHeight(event.target.value)} required/><br/>
<label className="labelIska">Weight: </label>
<input type="number" className="formFields" id="form-date"
onChange={event => setWeight(event.target.value)} required/><br/>
<label className="labelIska">Hospital: </label>
<input type="text" className="formFields" id="form-hospital"
onChange={event => setHospital(event.target.value)} required/><br/>
<br/>
<label className="labelIska">Presciption: </label><br/>
<textarea className="formFields" id="form-prescription"
onChange={event => setPrescription(event.target.value)}/><br/>
<span id="form-ka-button">
<button type="submit" className="button" disabled={loadingIncrement} onClick={addRecord}>
{loadingIncrement ? (
<span>
<i className="fas fa-spinner fa-spin"></i> Please wait
</span>
) : (
<span>
<i className="fas fa-plus"></i> Add Record
</span>
)}
</button>
</span>
</form>
</div>
);
};
export default Records;
|