From 3e2b4a46e242763b2c2099546f85439da735a632 Mon Sep 17 00:00:00 2001 From: WRadoslaw Date: Fri, 17 Nov 2023 16:07:15 +0100 Subject: [PATCH] Show success modal on market creation --- .../_crt/MarketDrawer/MarketDrawer.tsx | 114 +++++++++++++----- .../MarketDrawer/steps/SaleSummaryStep.tsx | 13 +- 2 files changed, 90 insertions(+), 37 deletions(-) diff --git a/packages/atlas/src/components/_crt/MarketDrawer/MarketDrawer.tsx b/packages/atlas/src/components/_crt/MarketDrawer/MarketDrawer.tsx index ab0f7f5b24..0d586b3943 100644 --- a/packages/atlas/src/components/_crt/MarketDrawer/MarketDrawer.tsx +++ b/packages/atlas/src/components/_crt/MarketDrawer/MarketDrawer.tsx @@ -1,14 +1,21 @@ -import { useCallback, useRef, useState } from 'react' +import { useApolloClient } from '@apollo/client' +import { useCallback, useMemo, useRef, useState } from 'react' import { flushSync } from 'react-dom' import { CSSTransition, SwitchTransition } from 'react-transition-group' +import { SvgActionLinkUrl, SvgActionMarket, SvgActionShoppingCart, SvgActionWarning } from '@/assets/icons' import { ActionDialogButtonProps } from '@/components/ActionBar' import { CrtDrawer } from '@/components/CrtDrawer' +import { TextButton } from '@/components/_buttons/Button' import { CrtMarketForm } from '@/components/_crt/MarketDrawer/MarketDrawer.types' import { MarketDrawerPreview } from '@/components/_crt/MarketDrawer/MarketDrawerPreview' import { MarketStep } from '@/components/_crt/MarketDrawer/steps/MarketStep' import { SaleSummaryStep } from '@/components/_crt/MarketDrawer/steps/SaleSummaryStep' +import { SuccessActionModalTemplate } from '@/components/_crt/SuccessActionModalTemplate' import { atlasConfig } from '@/config' +import { absoluteRoutes } from '@/config/routes' +import { useClipboard } from '@/hooks/useClipboard' +import { useUser } from '@/providers/user/user.hooks' import { transitions } from '@/styles' enum MARKET_STEPS { @@ -25,6 +32,7 @@ export type CrtMarketSaleViewProps = { export const MarketDrawer = ({ show, onClose, tokenName }: CrtMarketSaleViewProps) => { const [activeStep, setActiveStep] = useState(MARKET_STEPS.market) + const [showSuccessModal, setShowSuccessModal] = useState(false) const [marketData, setMarketData] = useState({ price: 10, tnc: atlasConfig.legal.crtTnc, @@ -34,6 +42,9 @@ export const MarketDrawer = ({ show, onClose, tokenName }: CrtMarketSaleViewProp const [secondaryButtonProps, setSecondaryButtonProps] = useState({ text: 'Back' }) const [isGoingBack, setIsGoingBack] = useState(false) const nodeRef = useRef(null) + const { channelId } = useUser() + const client = useApolloClient() + const { copyToClipboard } = useClipboard() const handleNextStep = useCallback( ({ price, tnc }: CrtMarketForm) => { @@ -72,38 +83,85 @@ export const MarketDrawer = ({ show, onClose, tokenName }: CrtMarketSaleViewProp setSecondaryButtonProps={setSecondaryButtonProps} handleBackClick={handleBackClick} handleCloseModal={onClose} + onSuccess={() => { + setShowSuccessModal(true) + onClose() + }} /> ) } } + const successDetails = useMemo( + () => [ + { + text: 'You can buy and sell your own tokens on the token market too!', + icon: , + }, + { + text: 'You don’t earn any royalties from the transactions of other members on the market.', + icon: , + }, + { + text: 'Members can now buy and sale your tokens on your token page. Share the link to the market with them to let everyone know about it.', + icon: , + actionNode: ( + copyToClipboard(absoluteRoutes.viewer.channel(channelId ?? '-1', { tab: 'Token' }))} + icon={} + > + Copy link to market + + ), + }, + ], + [channelId, copyToClipboard] + ) + return ( - } - > - - { - nodeRef.current?.addEventListener('transitionend', done, false) - }} - onEntered={() => setIsGoingBack(false)} - classNames={isGoingBack ? transitions.names.backwardSlideSwitch : transitions.names.forwardSlideSwitch} - > -
{stepContent()}
-
-
-
+ <> + { + client.refetchQueries({ include: 'active' }).then(() => { + setShowSuccessModal(false) + }) + }, + }} + /> + + } + > + + { + nodeRef.current?.addEventListener('transitionend', done, false) + }} + onEntered={() => setIsGoingBack(false)} + classNames={isGoingBack ? transitions.names.backwardSlideSwitch : transitions.names.forwardSlideSwitch} + > +
{stepContent()}
+
+
+
+ ) } diff --git a/packages/atlas/src/components/_crt/MarketDrawer/steps/SaleSummaryStep.tsx b/packages/atlas/src/components/_crt/MarketDrawer/steps/SaleSummaryStep.tsx index 14f1521469..222163b35f 100644 --- a/packages/atlas/src/components/_crt/MarketDrawer/steps/SaleSummaryStep.tsx +++ b/packages/atlas/src/components/_crt/MarketDrawer/steps/SaleSummaryStep.tsx @@ -1,4 +1,3 @@ -import { useApolloClient } from '@apollo/client' import { FC, useEffect } from 'react' import { SvgAlertsInformative24 } from '@/assets/icons' @@ -22,6 +21,7 @@ type SaleSummaryProps = { setSecondaryButtonProps: (props: ActionDialogButtonProps) => void handleBackClick: () => void handleCloseModal: () => void + onSuccess: () => void } export const SaleSummaryStep: FC = ({ @@ -30,13 +30,13 @@ export const SaleSummaryStep: FC = ({ setPrimaryButtonProps, handleBackClick, handleCloseModal, + onSuccess, }) => { const { fullFee } = useFee('startAmmTx', ['1', '1', 1, price]) const { tokenPrice } = useJoystream() const handleTransaction = useTransaction() const { displaySnackbar } = useSnackbar() const { joystream, proxyCallback } = useJoystream() - const client = useApolloClient() const { memberId, channelId } = useUser() useEffect(() => { @@ -48,12 +48,7 @@ export const SaleSummaryStep: FC = ({ txFactory: async (updateStatus) => (await joystream.extrinsics).startAmm(memberId, channelId, tokenPrice, price, proxyCallback(updateStatus)), onTxSync: async () => { - displaySnackbar({ - title: 'Success', - iconType: 'success', - }) - client.refetchQueries({ include: 'active' }) - handleCloseModal() + onSuccess() }, onError: () => { displaySnackbar({ @@ -72,13 +67,13 @@ export const SaleSummaryStep: FC = ({ }) }, [ channelId, - client, displaySnackbar, handleBackClick, handleCloseModal, handleTransaction, joystream, memberId, + onSuccess, price, proxyCallback, setPrimaryButtonProps,