11import React from 'react' ;
2- import { Wizard , WizardStep } from '../Wizard' ;
2+ import Lottie , { LottieRef } from 'lottie-react' ;
3+ import { Wizard , WizardStep , useWizard } from '../Wizard' ;
34import Input from '../../form/Input' ;
45import Checkbox from '../../form/checkbox/Checkbox' ;
56import CardRadioGroup from '../../card-interactive/CardRadioGroup' ;
67import CardCheckbox from '../../card-interactive/CardCheckbox' ;
78import Text from '../../text/Text' ;
9+ import Headline from '../../text/Headline' ;
810import Flex from '../../flex/Flex' ;
911import SelectMenu from '../../select-menu/SelectMenu' ;
1012import Icon from '../../icons/Icon' ;
@@ -13,6 +15,8 @@ import Avatar from '../../avatar/Avatar';
1315import SubjectIcon from '../../subject-icons/SubjectIcon' ;
1416import Spinner from '../../spinner/Spinner' ;
1517import FileHandler from '../../file-handler/FileHandler' ;
18+ import brandHeroesAnimation from './brand-heroes-lottie.json' ;
19+ import confettiAnimation from './confetti-lottie.json' ;
1620
1721const SubjectCardCheckbox = ( {
1822 name,
@@ -84,6 +88,95 @@ const AccountTypeCardRadio = ({
8488 ) ;
8589} ;
8690
91+ const SuccessStep = ( { avatarImage} : { avatarImage : string } ) => {
92+ const { currentStep, stepsLength} = useWizard ( ) ;
93+ const [ countdown , setCountdown ] = React . useState ( 3 ) ;
94+ const confettiAnimationRef : LottieRef = React . useRef ( ) ;
95+
96+ React . useEffect ( ( ) => {
97+ let countdown = 3 ;
98+
99+ if ( currentStep === stepsLength - 1 ) {
100+ console . log ( confettiAnimationRef . current ) ;
101+ if ( confettiAnimationRef . current ) {
102+ confettiAnimationRef . current . play ( ) ;
103+ }
104+
105+ const intervalID = window . setInterval ( ( ) => {
106+ if ( countdown === 0 ) {
107+ window . clearInterval ( intervalID ) ;
108+ }
109+
110+ setCountdown ( countdown ) ;
111+ countdown = countdown - 1 ;
112+ } , 1000 ) ;
113+
114+ return ( ) => {
115+ window . clearInterval ( intervalID ) ;
116+ } ;
117+ }
118+ } , [ currentStep , stepsLength ] ) ;
119+
120+ return (
121+ < >
122+ < div
123+ style = { {
124+ position : 'absolute' ,
125+ height : '30%' ,
126+ top : '10%' ,
127+ left : 0 ,
128+ width : '100%' ,
129+ } }
130+ >
131+ < Flex
132+ direction = "column"
133+ alignItems = "center"
134+ fullWidth
135+ fullHeight
136+ gap = "s"
137+ >
138+ < Avatar imgSrc = { avatarImage } size = "xl" />
139+ < Headline align = "to-center" size = "large" >
140+ Welcome to Brainly, YourUsername
141+ </ Headline >
142+ < Text align = "to-center" color = "text-gray-50" weight = "bold" >
143+ { countdown > 0
144+ ? `Redirecting to your question in... ${ countdown } s`
145+ : null }
146+ </ Text >
147+ </ Flex >
148+ </ div >
149+ < div
150+ style = { {
151+ position : 'absolute' ,
152+ height : '70%' ,
153+ width : '80%' ,
154+ top : '20%' ,
155+ left : '10%' ,
156+ } }
157+ >
158+ < Lottie animationData = { brandHeroesAnimation } />
159+ </ div >
160+ < div
161+ style = { {
162+ position : 'absolute' ,
163+ height : '80%' ,
164+ width : '80%' ,
165+ top : 0 ,
166+ left : '10%' ,
167+ } }
168+ >
169+ < Lottie
170+ lottieRef = { confettiAnimationRef }
171+ animationData = { confettiAnimation }
172+ loop = { false }
173+ autoplay = { false }
174+ />
175+ </ div >
176+ </ >
177+ ) ;
178+ } ;
179+
87180const CreateAccountStory = ( ) => {
88181 const years = React . useMemo ( ( ) => {
89182 const arr = [ ] ;
@@ -114,14 +207,12 @@ const CreateAccountStory = () => {
114207 setCountry ( [ option ] ) ;
115208 } , [ ] ) ;
116209
117- const [ uploadStatus , setUploadStatus ] = React . useState ( 'idle' ) ;
118-
119- const handleUpload = React . useCallback ( ( ) => {
120- setUploadStatus ( 'in_progress' ) ;
210+ const [ avatarImage , setAvatarImage ] = React . useState (
211+ 'images/pinguin_avatar.png'
212+ ) ;
121213
122- setTimeout ( ( ) => {
123- setUploadStatus ( 'completed' ) ;
124- } , 2000 ) ;
214+ const handleRandomize = React . useCallback ( ( ) => {
215+ setAvatarImage ( 'images/cat.png' ) ;
125216 } , [ ] ) ;
126217
127218 return (
@@ -201,27 +292,24 @@ const CreateAccountStory = () => {
201292 < WizardStep >
202293 < WizardStep . Title > Set your profile picture</ WizardStep . Title >
203294 < Flex gap = "l" marginBottom = "m" >
204- < Avatar imgSrc = "images/pinguin_avatar.png" size = "xl" />
295+ < Avatar imgSrc = { avatarImage } size = "xl" />
205296 < Flex direction = "column" gap = "s" >
206297 < Flex gap = "xs" >
207298 < Button
208299 variant = "solid-light"
209300 icon = { < Icon color = "icon-black" type = "reload" /> }
210301 type = "button"
302+ onClick = { handleRandomize }
211303 >
212304 Randomize
213305 </ Button >
214- { uploadStatus === 'idle' || uploadStatus === 'completed' ? (
215- < Button
216- variant = "solid-light"
217- icon = { < Icon color = "icon-black" type = "arrow_up" /> }
218- type = "button"
219- onClick = { handleUpload }
220- >
221- Upload
222- </ Button >
223- ) : null }
224- { uploadStatus === 'in_progress' ? < Spinner /> : null }
306+ < Button
307+ variant = "solid-light"
308+ icon = { < Icon color = "icon-black" type = "arrow_up" /> }
309+ type = "button"
310+ >
311+ Upload
312+ </ Button >
225313 </ Flex >
226314 < Text size = "small" >
227315 File that is{ ' ' }
@@ -239,11 +327,6 @@ const CreateAccountStory = () => {
239327 </ Text >
240328 </ Flex >
241329 </ Flex >
242- { uploadStatus === 'completed' ? (
243- < Flex >
244- < FileHandler > avatar.jpg</ FileHandler >
245- </ Flex >
246- ) : null }
247330 < WizardStep . Submit variant = "solid-indigo" > next</ WizardStep . Submit >
248331 </ WizardStep >
249332 < WizardStep >
@@ -281,6 +364,9 @@ const CreateAccountStory = () => {
281364 create account
282365 </ WizardStep . Submit >
283366 </ WizardStep >
367+ < WizardStep >
368+ < SuccessStep avatarImage = { avatarImage } />
369+ </ WizardStep >
284370 </ Wizard >
285371 ) ;
286372} ;
0 commit comments