fix property field, added default value of seed
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import Sidebar from '../../partials/Sidebar';
|
import Sidebar from '../../partials/Sidebar';
|
||||||
import Header from '../../partials/Header';
|
import Header from '../../partials/Header';
|
||||||
import ProfileTable from '../../partials/digitalId/ProfileTable';
|
import ProfileTable from '../../partials/digitalId/ProfileTable';
|
||||||
@@ -21,26 +21,29 @@ function Profile () {
|
|||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
property: '',
|
property: '',
|
||||||
value: '',
|
value: '',
|
||||||
seed: '',
|
seed: Math.floor(Math.random() * 90000000000000000000)
|
||||||
blockchained: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialPropertyValues = ['First name', 'Second name', 'Birthdate', 'Gender', 'Residence', 'Document type', 'Document ID', 'Issue date', 'Expiry date'];
|
const initialPropertyValues = ['First name', 'Second name', 'Birthdate', 'Gender', 'Residence', 'Document type', 'Document ID', 'Issue date', 'Expiry date'];
|
||||||
const [propertyValues, setPropertyValues] = useState(initialPropertyValues);
|
const [propertyValues, setPropertyValues] = useState(initialPropertyValues);
|
||||||
const [currentValues, setCurrentValues] = useState(defaultValues);
|
const [currentValues, setCurrentValues] = useState(defaultValues);
|
||||||
|
|
||||||
const openHint = () => {
|
const openHint = () => {
|
||||||
|
if (!currentValues.property) {
|
||||||
|
setPropertyValues(initialPropertyValues);
|
||||||
setHintOpen(true);
|
setHintOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const changeCurrentValues = (text, field) => {
|
|
||||||
setCurrentValues((prevState)=> ({
|
|
||||||
...prevState,
|
|
||||||
[field]: text,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeHint = (text) => {
|
const changeCurrentValues = (value, field) => {
|
||||||
currentValues.property = text;
|
setCurrentValues((prevState)=> ({
|
||||||
|
...prevState,
|
||||||
|
[field]: value.charAt(0).toUpperCase()+value.slice(1),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeHint = (element) => {
|
||||||
|
changeCurrentValues(element, 'property');
|
||||||
setHintOpen(false);
|
setHintOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +69,17 @@ function Profile () {
|
|||||||
setButtonPanelOpen(false);
|
setButtonPanelOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sendValues = () => {
|
||||||
|
if (!userData.some((element) => element.property === currentValues.property) && (currentValues.seed.toString().length === 20)) {
|
||||||
|
setAddPanelOpen(false);
|
||||||
|
setButtonPanelOpen(true);
|
||||||
|
setCurrentValues(defaultValues);
|
||||||
|
setHintOpen(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const cancelAddPanel = () => {
|
const cancelAddPanel = () => {
|
||||||
|
setCurrentValues(defaultValues);
|
||||||
setAddPanelOpen(false);
|
setAddPanelOpen(false);
|
||||||
setButtonPanelOpen(true);
|
setButtonPanelOpen(true);
|
||||||
}
|
}
|
||||||
@@ -81,10 +94,17 @@ function Profile () {
|
|||||||
setButtonPanelOpen(true);
|
setButtonPanelOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInput = (text) => {
|
const handleInput = (text, field) => {
|
||||||
|
changeCurrentValues(text, field);
|
||||||
setPropertyValues(initialPropertyValues);
|
setPropertyValues(initialPropertyValues);
|
||||||
|
setHintOpen(true);
|
||||||
|
if (text) {
|
||||||
let reg = new RegExp(`^${text}`, 'img');
|
let reg = new RegExp(`^${text}`, 'img');
|
||||||
setPropertyValues((prevState) => prevState.filter((element) => element.match(reg)));
|
setPropertyValues((prevState) => prevState.filter((element) => element.match(reg)));
|
||||||
|
if (propertyValues.length === 0) {
|
||||||
|
setHintOpen(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const userData = [
|
const userData = [
|
||||||
@@ -285,8 +305,8 @@ function Profile () {
|
|||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
onClick={openHint}
|
onClick={openHint}
|
||||||
onInput={(e) => handleInput(e.target.value)}
|
onInput={(e) => handleInput(e.target.value, 'property')}
|
||||||
onChange={(e) => changeCurrentValues(e.target.value, 'property')}
|
value={currentValues.property}
|
||||||
/>
|
/>
|
||||||
<div className={`flex flex-col gap-y-2 py-2 pl-2 border border-t-0 border-slate-200 rounded ${hintOpen || 'hidden'}`}>
|
<div className={`flex flex-col gap-y-2 py-2 pl-2 border border-t-0 border-slate-200 rounded ${hintOpen || 'hidden'}`}>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -303,7 +323,9 @@ function Profile () {
|
|||||||
className="form-input w-full"
|
className="form-input w-full"
|
||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
onChange={(event) => changeCurrentValues(event.target.value, 'property')}
|
onClick={() => setHintOpen(false)}
|
||||||
|
onChange={(e) => changeCurrentValues(e.target.value, 'value')}
|
||||||
|
value={currentValues.value}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -313,7 +335,9 @@ function Profile () {
|
|||||||
className="form-input w-full"
|
className="form-input w-full"
|
||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
onChange={(event) => changeCurrentValues(event.target.value, 'property')}
|
onClick={() => setHintOpen(false)}
|
||||||
|
onChange={(e) => changeCurrentValues(e.target.value, 'seed')}
|
||||||
|
value={currentValues.seed}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -321,7 +345,7 @@ function Profile () {
|
|||||||
<span className="block text-sm font-medium">Store data on blockchain</span>
|
<span className="block text-sm font-medium">Store data on blockchain</span>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="form-switch">
|
<div className="form-switch">
|
||||||
<input type="checkbox" id="switch-1" className="sr-only" checked={toggle} onChange={() => setToggle(!toggle)} />
|
<input type="checkbox" id="blockcheined" className="sr-only" checked={toggle} onChange={() => setToggle(!toggle)} />
|
||||||
<label className="bg-slate-400" htmlFor="switch-1">
|
<label className="bg-slate-400" htmlFor="switch-1">
|
||||||
<span className="bg-white shadow-sm" aria-hidden="true"></span>
|
<span className="bg-white shadow-sm" aria-hidden="true"></span>
|
||||||
</label>
|
</label>
|
||||||
@@ -338,7 +362,7 @@ function Profile () {
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="btn-sm bg-indigo-500 hover:bg-indigo-600 text-white"
|
className="btn-sm bg-indigo-500 hover:bg-indigo-600 text-white"
|
||||||
onClick={cancelAddPanel}
|
onClick={sendValues}
|
||||||
>
|
>
|
||||||
Send
|
Send
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user