market/src/components/Publish/Actions/index.tsx

119 lines
3.3 KiB
TypeScript
Raw Normal View History

2021-11-26 12:03:55 +01:00
import React, { FormEvent, ReactElement, RefObject } from 'react'
import Button from '@shared/atoms/Button'
import styles from './index.module.css'
import { FormikContextType, useFormikContext } from 'formik'
import { FormPublishData } from '../_types'
import { wizardSteps } from '../_constants'
2022-01-12 17:59:32 +01:00
import SuccessConfetti from '@shared/SuccessConfetti'
Unsupported Network Tooltip (#1331) * Moving isSupportedOceanNetwork to Web3 context * Removing page title and replacing it with a warning message * Creating Error state in title for the wrong network * Creating UnsupportedNetwrok component * Adding different networks into tooltip * Adding button + styling * Adding change netwrok function * Adding Change Network tooltip to submit page * Reducing code duplication * Removing unnecessary changes * Fixing logic for checking which chainIds are supported * Simplifying isSupportedOceanNetwork check logic * Default to not showing unsupported network message when no wallet is connected * Always showing available networks in tooltip * Adding info icon to action button * adding padding to AvailableNetworks component * Changing label to list components * Changing brand-white to currentColor * Revert "Changing brand-white to currentColor" This reverts commit 278f0d4ab9e38f23985b2f29f7ff11625a7d14d7. * CHanging --brand-white to currentColor * Info Icon in currentColor * Changing NetworkOptions component name to Network * Simplifying tooltip logic in title * Removing unused classname * Fixing repeating <ul> issue * Removing unused class * Refactoring AvailableNetworks component into src/components/Publish * Moving tooltip message into content/publish/index.json * Reducing duplication in css * Removing duplication of infoIcon css styles * Tidying up logic in setIsSupportedOceanNetwork useEffect * Updating setIsSupportedOceanNetwork effect dependancies * merge fixes for new MarketMetadata context Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2022-04-22 02:54:04 +02:00
import { useWeb3 } from '@context/Web3'
import { useRouter } from 'next/router'
Unsupported Network Tooltip (#1331) * Moving isSupportedOceanNetwork to Web3 context * Removing page title and replacing it with a warning message * Creating Error state in title for the wrong network * Creating UnsupportedNetwrok component * Adding different networks into tooltip * Adding button + styling * Adding change netwrok function * Adding Change Network tooltip to submit page * Reducing code duplication * Removing unnecessary changes * Fixing logic for checking which chainIds are supported * Simplifying isSupportedOceanNetwork check logic * Default to not showing unsupported network message when no wallet is connected * Always showing available networks in tooltip * Adding info icon to action button * adding padding to AvailableNetworks component * Changing label to list components * Changing brand-white to currentColor * Revert "Changing brand-white to currentColor" This reverts commit 278f0d4ab9e38f23985b2f29f7ff11625a7d14d7. * CHanging --brand-white to currentColor * Info Icon in currentColor * Changing NetworkOptions component name to Network * Simplifying tooltip logic in title * Removing unused classname * Fixing repeating <ul> issue * Removing unused class * Refactoring AvailableNetworks component into src/components/Publish * Moving tooltip message into content/publish/index.json * Reducing duplication in css * Removing duplication of infoIcon css styles * Tidying up logic in setIsSupportedOceanNetwork useEffect * Updating setIsSupportedOceanNetwork effect dependancies * merge fixes for new MarketMetadata context Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2022-04-22 02:54:04 +02:00
import Tooltip from '@shared/atoms/Tooltip'
import AvailableNetworks from 'src/components/Publish/AvailableNetworks'
import Info from '@images/info.svg'
2021-11-01 16:38:53 +01:00
export default function Actions({
2022-01-12 17:59:32 +01:00
scrollToRef,
did
2021-11-01 16:38:53 +01:00
}: {
scrollToRef: RefObject<any>
2022-01-12 17:59:32 +01:00
did: string
2021-11-01 16:38:53 +01:00
}): ReactElement {
const router = useRouter()
Unsupported Network Tooltip (#1331) * Moving isSupportedOceanNetwork to Web3 context * Removing page title and replacing it with a warning message * Creating Error state in title for the wrong network * Creating UnsupportedNetwrok component * Adding different networks into tooltip * Adding button + styling * Adding change netwrok function * Adding Change Network tooltip to submit page * Reducing code duplication * Removing unnecessary changes * Fixing logic for checking which chainIds are supported * Simplifying isSupportedOceanNetwork check logic * Default to not showing unsupported network message when no wallet is connected * Always showing available networks in tooltip * Adding info icon to action button * adding padding to AvailableNetworks component * Changing label to list components * Changing brand-white to currentColor * Revert "Changing brand-white to currentColor" This reverts commit 278f0d4ab9e38f23985b2f29f7ff11625a7d14d7. * CHanging --brand-white to currentColor * Info Icon in currentColor * Changing NetworkOptions component name to Network * Simplifying tooltip logic in title * Removing unused classname * Fixing repeating <ul> issue * Removing unused class * Refactoring AvailableNetworks component into src/components/Publish * Moving tooltip message into content/publish/index.json * Reducing duplication in css * Removing duplication of infoIcon css styles * Tidying up logic in setIsSupportedOceanNetwork useEffect * Updating setIsSupportedOceanNetwork effect dependancies * merge fixes for new MarketMetadata context Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2022-04-22 02:54:04 +02:00
const { isSupportedOceanNetwork } = useWeb3()
const {
values,
errors,
isValid,
isSubmitting,
setFieldValue
}: FormikContextType<FormPublishData> = useFormikContext()
const { connect, accountId } = useWeb3()
async function handleActivation(e: FormEvent<HTMLButtonElement>) {
// prevent accidentially submitting a form the button might be in
e.preventDefault()
await connect()
}
function handleAction(action: string) {
const currentStep: string = router.query.step as string
router.push({
pathname: `${router.pathname}`,
query: { step: parseInt(currentStep) + (action === 'next' ? +1 : -1) }
})
scrollToRef.current.scrollIntoView()
}
function handleNext(e: FormEvent) {
e.preventDefault()
handleAction('next')
}
function handlePrevious(e: FormEvent) {
e.preventDefault()
handleAction('prev')
}
const isContinueDisabled =
(values.user.stepCurrent === 1 && errors.metadata !== undefined) ||
(values.user.stepCurrent === 2 && errors.services !== undefined) ||
(values.user.stepCurrent === 3 && errors.pricing !== undefined)
return (
<footer className={styles.actions}>
2022-01-12 17:59:32 +01:00
{did ? (
<SuccessConfetti
success="Successfully published!"
action={
<Button style="primary" to={`/asset/${did}`}>
View Asset
</Button>
}
/>
) : (
2022-01-12 17:59:32 +01:00
<>
{values.user.stepCurrent > 1 && (
<Button onClick={handlePrevious} disabled={isSubmitting}>
Back
</Button>
)}
{values.user.stepCurrent < wizardSteps.length ? (
<Button
style="primary"
onClick={handleNext}
disabled={isContinueDisabled}
>
Continue
</Button>
) : !accountId ? (
<Button type="submit" style="primary" onClick={handleActivation}>
Connect Wallet
</Button>
Unsupported Network Tooltip (#1331) * Moving isSupportedOceanNetwork to Web3 context * Removing page title and replacing it with a warning message * Creating Error state in title for the wrong network * Creating UnsupportedNetwrok component * Adding different networks into tooltip * Adding button + styling * Adding change netwrok function * Adding Change Network tooltip to submit page * Reducing code duplication * Removing unnecessary changes * Fixing logic for checking which chainIds are supported * Simplifying isSupportedOceanNetwork check logic * Default to not showing unsupported network message when no wallet is connected * Always showing available networks in tooltip * Adding info icon to action button * adding padding to AvailableNetworks component * Changing label to list components * Changing brand-white to currentColor * Revert "Changing brand-white to currentColor" This reverts commit 278f0d4ab9e38f23985b2f29f7ff11625a7d14d7. * CHanging --brand-white to currentColor * Info Icon in currentColor * Changing NetworkOptions component name to Network * Simplifying tooltip logic in title * Removing unused classname * Fixing repeating <ul> issue * Removing unused class * Refactoring AvailableNetworks component into src/components/Publish * Moving tooltip message into content/publish/index.json * Reducing duplication in css * Removing duplication of infoIcon css styles * Tidying up logic in setIsSupportedOceanNetwork useEffect * Updating setIsSupportedOceanNetwork effect dependancies * merge fixes for new MarketMetadata context Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2022-04-22 02:54:04 +02:00
) : !isSupportedOceanNetwork ? (
<Tooltip content={<AvailableNetworks />}>
<Button
type="submit"
style="primary"
disabled
className={styles.infoButton}
>
Unsupported Network <Info className={styles.infoIcon} />
</Button>
</Tooltip>
2022-01-12 17:59:32 +01:00
) : (
<Button
type="submit"
style="primary"
disabled={isSubmitting || !isValid}
>
2022-01-12 17:59:32 +01:00
Submit
</Button>
)}
</>
)}
</footer>
)
}