Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useEffect, useRef, useState } from 'react';
- import ChatBubble from './ChatBubble/ChatBubble';
- import classes from './Chat.module.css';
- import ScrollAnimation from 'react-animate-on-scroll';
- import Typist from 'react-typist';
- const Chat = () => {
- const [state, setState] = useState(0);
- const [showInputText, setShowInputText] = useState(false);
- const choices = [{ text: 'Under 2 år siden' }, { text: 'Over 2 år siden' }];
- const choices2 = [{ text: 'Ja' }, { text: 'Nej' }];
- const typistCursor = {
- hideWhenDone: true,
- hideWhenDoneDelay: 200
- };
- const inputText = <Typist cursor={typistCursor}>test@mail.com</Typist>;
- const renderNextBubble = () => {
- const newState = state + 1;
- setState(newState);
- console.log('test state', state);
- };
- return (
- <div className={classes.chatWrapper}>
- <ChatBubble
- isReply={false}
- animationDelay={0}
- animationCallback={renderNextBubble}
- chatChoices={choices}
- >
- <p>Hvornår købte du din vare?</p>
- </ChatBubble>
- {state >= 1 ? (
- <ChatBubble
- isReply={true}
- animationDelay={0}
- animationCallback={renderNextBubble}
- >
- Under 2 år siden
- </ChatBubble>
- ) : null}
- {state >= 2 ? (
- <ChatBubble
- isReply={false}
- animationDelay={0}
- animationCallback={renderNextBubble}
- chatChoices={choices2}
- >
- <p>Er det under 6 måneder siden at du bestilte/modtog dit køb?</p>
- </ChatBubble>
- ) : null}
- {state >= 3 ? (
- <ScrollAnimation
- animateIn="fadeIn"
- duration={0.5}
- delay={-0.25}
- animateOnce={true}
- afterAnimatedIn={renderNextBubble}
- >
- <div className={classes.DotContainer}>
- <div className={classes.Dot}></div>
- </div>
- </ScrollAnimation>
- ) : null}
- {state >= 4 ? (
- <ScrollAnimation
- animateIn="fadeIn"
- duration={0.5}
- delay={-0.25}
- animateOnce={true}
- afterAnimatedIn={renderNextBubble}
- >
- <div className={classes.DotContainer}>
- <div className={classes.Dot}></div>
- </div>
- </ScrollAnimation>
- ) : null}
- {state >= 5 ? (
- <ScrollAnimation
- animateIn="fadeIn"
- duration={0.5}
- delay={-0.25}
- animateOnce={true}
- afterAnimatedIn={renderNextBubble}
- >
- <div className={classes.DotContainer}>
- <div className={classes.Dot}></div>
- </div>
- </ScrollAnimation>
- ) : null}
- {state >= 6 ? (
- <>
- <ChatBubble
- isReply={false}
- animationDelay={0}
- animationCallback={renderNextBubble}
- >
- <p style={{ fontWeight: 'bold' }}>Du er næsten færdig</p>
- <p>
- Skriv din email nedenunder, så har vi en mulighed for at sende
- klagen til dig
- </p>
- <p style={{ fontWeight: 'bold' }}>
- Dobbelttjek at du har skrevet den rigtige mail!
- </p>
- </ChatBubble>
- <div className={classes.EmailInput}>
- {setTimeout(() => {
- console.log('executing timeout');
- setShowInputText(true);
- }, 1000)}
- {showInputText ? (
- inputText
- ) : (
- <div className={classes.InputText}>Indtast din email her...</div>
- )}
- </div>
- </>
- ) : null}
- </div>
- );
- };
- export default Chat;
Add Comment
Please, Sign In to add comment