Merge pull request #33 from franze6/DID-6

Refactoring in Onboarding steps
This commit is contained in:
DuCay
2022-07-08 21:24:21 +03:00
committed by GitHub
3 changed files with 35 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
import React, {useEffect, useState} from 'react'; import React, {useState} from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { registrationStore } from "../store/store"; import { registrationStore } from "../store/store";
@@ -24,36 +24,22 @@ const Onboarding2 = observer(()=>{
...dataRegistration, ...dataRegistration,
[event.target.id]: newValue [event.target.id]: newValue
}) })
if(!Object.keys(dataRegistration).find(item=>!dataRegistration[item])) {
setFillingForm(true)
}
} }
const saveStoreRegistration = ()=>{ const saveStoreRegistration = ()=>{
Object.keys(dataRegistration).forEach(item=>{ if(fillingForm) {
let element=document.getElementById(item) registrationStore.saveDataRegistration(Object.keys(dataRegistration).map(item=>{
if(dataRegistration[item]) { return{
element.style.borderColor="" key: `${item}`,
} else { value: dataRegistration[item]
element.style.borderColor="red" }
} }))
})
if(Object.keys(dataRegistration).find(item=>!dataRegistration[item])) {
return
} else {
setFillingForm(true)
} }
registrationStore.saveDataRegistration(Object.keys(dataRegistration).map(item=>{
return{
key: `${item}`,
value: dataRegistration[item]
}
}))
} }
useEffect(()=>{
if(fillingForm===true) {
document.getElementById("signup").click()
}
},[fillingForm])
return ( return (
<main className="bg-white"> <main className="bg-white">

View File

@@ -6,19 +6,18 @@ import {registrationStore} from "../store/store";
import { passphrase } from "@liskhq/lisk-client"; import { passphrase } from "@liskhq/lisk-client";
function Onboarding3() { function Onboarding3() {
const [passPhrase, setPassPhrase] = useState(registrationStore.passPhrase.replace(/\s+/g, ' ').split(' ').map((item, index) => ({str:item, id:index }))) const [passPhrase, setPassPhrase] = useState(convertPhraseToArray(registrationStore.passPhrase))
function generatePassPhrase() { function generatePassPhrase() {
let phrase = passphrase.Mnemonic.generateMnemonic() let phrase = passphrase.Mnemonic.generateMnemonic()
registrationStore.savePassPhrase(phrase) registrationStore.savePassPhrase(phrase)
let newPassPhrase = registrationStore.passPhrase.split(' ').map((item, index) => ({str:item, id:index })) setPassPhrase(convertPhraseToArray(registrationStore.passPhrase))
setPassPhrase(newPassPhrase)
} }
function savePassPhraseInStore (copiedPhrase) { function savePassPhraseInStore (copiedPhrase) {
let phrasePaste = copiedPhrase.trim().replace(/\s+/g, ' ').split(' ') let phrasePaste = convertPhraseToArray(copiedPhrase.trim())
if(phrasePaste.length===12) { if(phrasePaste.length===12) {
registrationStore.savePassPhrase(copiedPhrase) registrationStore.savePassPhrase(copiedPhrase.trim())
setPassPhrase(phrasePaste.map((item, index) => ({str:item, id:index }))) setPassPhrase(phrasePaste)
} else { } else {
return false return false
} }
@@ -28,6 +27,10 @@ function Onboarding3() {
navigator.clipboard.readText().then(res=>savePassPhraseInStore(res)) navigator.clipboard.readText().then(res=>savePassPhraseInStore(res))
} }
function convertPhraseToArray(phrase) {
return phrase.split(' ').map((item, index) => ({str:item, id:index }))
}
return ( return (
<main className="bg-white"> <main className="bg-white">

View File

@@ -1,4 +1,4 @@
import React, {useEffect, useState} from 'react'; import React, {useState} from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import {generateSvgAvatar} from "../images/GenerateOnboardingSvg/GenerateSvg"; import {generateSvgAvatar} from "../images/GenerateOnboardingSvg/GenerateSvg";
import Logo from "../images/logo.png"; import Logo from "../images/logo.png";
@@ -7,23 +7,23 @@ import { registrationStore } from "../store/store";
const Onboarding4 = observer(()=>{ const Onboarding4 = observer(()=>{
const [checkBoxesSelected, setCheckBoxesSelected] = useState(false) const [checkBoxesSelected, setCheckBoxesSelected] = useState([])
function createAccount () { function createAccount () {
let checkBoxes=[...document.getElementsByClassName("form-checkbox")] if(checkBoxesSelected.length===2) {
if(checkBoxes.find(item=>item.checked===false)) {
return
} else {
registrationStore.pushAccountData() registrationStore.pushAccountData()
setCheckBoxesSelected(true)
} }
} }
useEffect(()=>{ function saveCheckBoxesValues(e) {
if(checkBoxesSelected===true) { const { id, checked } = e.target
document.getElementById("link-dashboard").click() setCheckBoxesSelected([...checkBoxesSelected, id])
if (!checked) {
setCheckBoxesSelected(checkBoxesSelected.filter(item=>item!==id))
} }
},[checkBoxesSelected]) }
const firstNameAccount = registrationStore.accountData.length && registrationStore.accountData.find(item=>item.key==="first_name").value
return ( return (
<main className="bg-white"> <main className="bg-white">
@@ -80,20 +80,20 @@ const Onboarding4 = observer(()=>{
<circle className="text-emerald-100" cx="32" cy="32" r="32" /> <circle className="text-emerald-100" cx="32" cy="32" r="32" />
<path className="text-emerald-500" d="m28.5 41-8-8 3-3 5 5 12-12 3 3z" /> <path className="text-emerald-500" d="m28.5 41-8-8 3-3 5 5 12-12 3 3z" />
</svg> </svg>
<h1 className="text-3xl text-slate-800 font-bold mb-8">{registrationStore.accountData.find(item=>item.key="first_name").key ? `Nice to meet you, ${registrationStore.accountData.find(item=>item.key="first_name").value} 🙌` : 'Please, go back step 2'}</h1> <h1 className="text-3xl text-slate-800 font-bold mb-8">{firstNameAccount ? `Nice to meet you, ${firstNameAccount} 🙌` : 'Please, go back step 2'}</h1>
<button onClick={()=>createAccount()} className="btn px-6 bg-indigo-500 hover:bg-indigo-600 text-white"> <button onClick={()=>createAccount()} className="btn px-6 bg-indigo-500 hover:bg-indigo-600 text-white">
<Link id="link-dashboard" to={checkBoxesSelected && "/dashboard"}>Go To Profile -&gt;</Link> <Link id="link-dashboard" to={checkBoxesSelected.length===2 && "/dashboard"}>Go To Profile -&gt;</Link>
</button> </button>
</div> </div>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="mr-1"> <div className="mr-1">
<label className="flex items-center"> <label className="flex items-center">
<input type="checkbox" className="form-checkbox" /> <input id="checkbox-1" onChange={(e)=>saveCheckBoxesValues(e)} type="checkbox" className="form-checkbox" />
<span className="text-sm ml-2">I understand that Idntty cannot recover pass phrase</span> <span className="text-sm ml-2">I understand that Idntty cannot recover pass phrase</span>
</label> </label>
<label className="flex items-center"> <label className="flex items-center">
<input type="checkbox" className="form-checkbox" /> <input id="checkbox-2" onChange={(e)=>saveCheckBoxesValues(e)} type="checkbox" className="form-checkbox" />
<div className="text-sm ml-2"> <div className="text-sm ml-2">
I <Link className="text-indigo-500 hover:text-indigo-600 underline" to="/">store my pharse</Link> very carefuly I <Link className="text-indigo-500 hover:text-indigo-600 underline" to="/">store my pharse</Link> very carefuly
</div> </div>