Guest User

Untitled

a guest
Feb 25th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useEffect, useRef, useState } from 'react';
  2. import ChatBubble from './ChatBubble/ChatBubble';
  3. import classes from './Chat.module.css';
  4. import ScrollAnimation from 'react-animate-on-scroll';
  5. import Typist from 'react-typist';
  6.  
  7. const Chat = () => {
  8.   const [state, setState] = useState(0);
  9.  
  10.   const [showInputText, setShowInputText] = useState(false);
  11.  
  12.   const choices = [{ text: 'Under 2 år siden' }, { text: 'Over 2 år siden' }];
  13.  
  14.   const choices2 = [{ text: 'Ja' }, { text: 'Nej' }];
  15.  
  16.   const typistCursor = {
  17.     hideWhenDone: true,
  18.     hideWhenDoneDelay: 200
  19.   };
  20.  
  21.   const inputText = <Typist cursor={typistCursor}>test@mail.com</Typist>;
  22.  
  23.   const renderNextBubble = () => {
  24.     const newState = state + 1;
  25.     setState(newState);
  26.     console.log('test state', state);
  27.   };
  28.  
  29.   return (
  30.     <div className={classes.chatWrapper}>
  31.  
  32.       <ChatBubble
  33.         isReply={false}
  34.         animationDelay={0}
  35.         animationCallback={renderNextBubble}
  36.         chatChoices={choices}
  37.       >
  38.         <p>Hvornår købte du din vare?</p>
  39.       </ChatBubble>
  40.  
  41.       {state >= 1 ? (
  42.         <ChatBubble
  43.           isReply={true}
  44.           animationDelay={0}
  45.           animationCallback={renderNextBubble}
  46.         >
  47.           Under 2 år siden
  48.         </ChatBubble>
  49.       ) : null}
  50.  
  51.       {state >= 2 ? (
  52.         <ChatBubble
  53.           isReply={false}
  54.           animationDelay={0}
  55.           animationCallback={renderNextBubble}
  56.           chatChoices={choices2}
  57.         >
  58.           <p>Er det under 6 måneder siden at du bestilte/modtog dit køb?</p>
  59.         </ChatBubble>
  60.       ) : null}
  61.  
  62.       {state >= 3 ? (
  63.         <ScrollAnimation
  64.           animateIn="fadeIn"
  65.           duration={0.5}
  66.           delay={-0.25}
  67.           animateOnce={true}
  68.           afterAnimatedIn={renderNextBubble}
  69.         >
  70.           <div className={classes.DotContainer}>
  71.             <div className={classes.Dot}></div>
  72.           </div>
  73.         </ScrollAnimation>
  74.       ) : null}
  75.       {state >= 4 ? (
  76.         <ScrollAnimation
  77.           animateIn="fadeIn"
  78.           duration={0.5}
  79.           delay={-0.25}
  80.           animateOnce={true}
  81.           afterAnimatedIn={renderNextBubble}
  82.         >
  83.           <div className={classes.DotContainer}>
  84.             <div className={classes.Dot}></div>
  85.           </div>
  86.         </ScrollAnimation>
  87.       ) : null}
  88.       {state >= 5 ? (
  89.         <ScrollAnimation
  90.           animateIn="fadeIn"
  91.           duration={0.5}
  92.           delay={-0.25}
  93.           animateOnce={true}
  94.           afterAnimatedIn={renderNextBubble}
  95.         >
  96.           <div className={classes.DotContainer}>
  97.             <div className={classes.Dot}></div>
  98.           </div>
  99.         </ScrollAnimation>
  100.       ) : null}
  101.  
  102.       {state >= 6 ? (
  103.         <>
  104.           <ChatBubble
  105.             isReply={false}
  106.             animationDelay={0}
  107.             animationCallback={renderNextBubble}
  108.           >
  109.             <p style={{ fontWeight: 'bold' }}>Du er næsten færdig</p>
  110.             <p>
  111.               Skriv din email nedenunder, så har vi en mulighed for at sende
  112.               klagen til dig
  113.             </p>
  114.             <p style={{ fontWeight: 'bold' }}>
  115.               Dobbelttjek at du har skrevet den rigtige mail!
  116.             </p>
  117.           </ChatBubble>
  118.           <div className={classes.EmailInput}>
  119.             {setTimeout(() => {
  120.               console.log('executing timeout');
  121.               setShowInputText(true);
  122.             }, 1000)}
  123.             {showInputText ? (
  124.               inputText
  125.             ) : (
  126.               <div className={classes.InputText}>Indtast din email her...</div>
  127.             )}
  128.           </div>
  129.         </>
  130.       ) : null}
  131.     </div>
  132.   );
  133. };
  134.  
  135. export default Chat;
Add Comment
Please, Sign In to add comment