Skip to content

Commit

Permalink
Remvoe localStorage caching and show "me" on InviteMembersForm (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
nramadas authored and jonathan3692bf committed Jun 16, 2022
1 parent 863683e commit 81fec66
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 28 deletions.
27 changes: 2 additions & 25 deletions components/NewRealmWizard/PageTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/router'

import useLocalStorageState from '@hooks/useLocalStorageState'
import { isWizardValid } from '@utils/formValidation'

import CreateDAOWizard from '@components/NewRealmWizard/CreateDAOWizard'
Expand All @@ -19,28 +18,18 @@ export const Section = ({ children }) => {

export default function FormPage({
type,
ssFormKey,
steps,
handleSubmit,
submissionPending,
}) {
const { connected, current: wallet } = useWalletStore((s) => s)
const userAddress = wallet?.publicKey?.toBase58()
const [formData, setFormData] = useLocalStorageState<any>(ssFormKey, {
const [formData, setFormData] = useState<any>({
memberAddresses: userAddress ? [userAddress] : undefined,
})
const { query, push } = useRouter()
const currentStep = formData?.currentStep || 0

useEffect(() => {
window.addEventListener('beforeunload', promptUserBeforeLeaving)
window.addEventListener('unload', purgeFormData)
return () => {
window.removeEventListener('beforeunload', promptUserBeforeLeaving)
window.removeEventListener('unload', purgeFormData)
}
}, [])

useEffect(() => {
async function tryToConnect() {
try {
Expand All @@ -64,17 +53,6 @@ export default function FormPage({
}
}, [currentStep])

function promptUserBeforeLeaving(ev) {
ev.preventDefault()
if (formData) {
ev.returnValue = true
}
}

function purgeFormData() {
setFormData({})
}

function handleNextButtonClick({ step: fromStep, data }) {
const updatedFormState = {
...formData,
Expand Down Expand Up @@ -109,7 +87,6 @@ export default function FormPage({
)

if (fromStep === 0) {
purgeFormData()
push(
{
pathname: '/realms/new/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { yupResolver } from '@hookform/resolvers/yup'
import * as yup from 'yup'
import clsx from 'clsx'

import useWalletStore from 'stores/useWalletStore'
import FormHeader from '@components/NewRealmWizard/components/FormHeader'
import FormField from '@components/NewRealmWizard/components/FormField'
import FormFooter from '@components/NewRealmWizard/components/FormFooter'
Expand Down Expand Up @@ -124,6 +125,8 @@ export default function InviteMembersForm({
currentStep,
totalSteps,
}) {
const { current } = useWalletStore((s) => s)
const userAddress = current?.publicKey?.toBase58()
const inputElement = useRef<HTMLInputElement>(null)
const [inviteList, setInviteList] = useState<string[]>([])
const [invalidAddresses, setInvalidAddresses] = useState<string[]>([])
Expand Down Expand Up @@ -249,6 +252,7 @@ export default function InviteMembersForm({
<InviteAddress
key={address}
address={address}
currentUser={address === userAddress}
index={index + 1}
onRemoveClick={() => removeAddressFromInviteList(address)}
/>
Expand Down
1 change: 0 additions & 1 deletion pages/realms/new/multisig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default function MultiSigWizard() {
return (
<FormPage
type={FORM_NAME}
ssFormKey={SESSION_STORAGE_FORM_KEY}
steps={steps}
handleSubmit={handleSubmit}
submissionPending={requestPending}
Expand Down
1 change: 0 additions & 1 deletion pages/realms/new/nft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export default function NFTWizard() {
return (
<FormPage
type={FORM_NAME}
ssFormKey={SESSION_STORAGE_FORM_KEY}
steps={steps}
handleSubmit={handleSubmit}
submissionPending={requestPending}
Expand Down
1 change: 0 additions & 1 deletion pages/realms/new/tokenized/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export default function GovTokenWizard() {
return (
<FormPage
type={FORM_NAME}
ssFormKey={SESSION_STORAGE_FORM_KEY}
steps={steps}
handleSubmit={handleSubmit}
submissionPending={requestPending}
Expand Down

0 comments on commit 81fec66

Please sign in to comment.