|
| 1 | +import { Dispatch, SetStateAction, useState } from 'react'; |
| 2 | + |
| 3 | +import ChatBot, { Params } from 'react-chatbotify'; |
| 4 | +import { formatPreviewIdToTitleCase } from '../../utils'; |
| 5 | + |
| 6 | +type DesktopThemePreviewProps = { |
| 7 | + previewIds: string[]; |
| 8 | + clearPreviewIds: () => void; |
| 9 | + setPreviewIds: Dispatch<SetStateAction<string[]>>; |
| 10 | +}; |
| 11 | + |
| 12 | +const DesktopThemePreview = ({ |
| 13 | + previewIds, |
| 14 | + clearPreviewIds, |
| 15 | + setPreviewIds, |
| 16 | +}: DesktopThemePreviewProps) => { |
| 17 | + // flow for interactive chatbot |
| 18 | + const flow = { |
| 19 | + start: { |
| 20 | + message: (params: Params) => { |
| 21 | + params.injectMessage( |
| 22 | + 'Hello 👋! Did you know? The order of specifying themes matters!' |
| 23 | + ); |
| 24 | + return 'Try previewing some themes below, or click on those on the left! 😊'; |
| 25 | + }, |
| 26 | + checkboxes: { items: ['Minimal Midnight', 'Cyborg', 'Terminal'] }, |
| 27 | + function: (params: Params) => { |
| 28 | + setPreviewIds( |
| 29 | + params.userInput.split(',').map((theme) => { |
| 30 | + if (theme === 'Minimal Midnight') { |
| 31 | + return 'minimal_midnight'; |
| 32 | + } else if (theme === 'Cyborg') { |
| 33 | + return 'cyborg'; |
| 34 | + } else { |
| 35 | + return 'terminal'; |
| 36 | + } |
| 37 | + }) |
| 38 | + ); |
| 39 | + }, |
| 40 | + chatDisabled: true, |
| 41 | + path: 'end', |
| 42 | + }, |
| 43 | + end: { |
| 44 | + message: "What's next? 😊", |
| 45 | + options: ['Try Again', 'Check Documentation', 'Discord'], |
| 46 | + path: (params: Params) => { |
| 47 | + if (params.userInput === 'Try Again') { |
| 48 | + setPreviewIds([]); |
| 49 | + } else if (params.userInput === 'Discord') { |
| 50 | + window.open('https://discord.gg/6R4DK4G5Zh'); |
| 51 | + } else if (params.userInput === 'Check Documentation') { |
| 52 | + window.open('https://react-chatbotify.com'); |
| 53 | + } else { |
| 54 | + setPreviewIds([]); |
| 55 | + params.injectMessage( |
| 56 | + "Hmmm I'm not sure what you said, but let's try again!" |
| 57 | + ); |
| 58 | + } |
| 59 | + return 'start'; |
| 60 | + }, |
| 61 | + }, |
| 62 | + }; |
| 63 | + |
| 64 | + console.log(previewIds) |
| 65 | + |
| 66 | + return ( |
| 67 | + <div className="h-screen bg-accent-800 p-5 w-[45rem] flex flex-col items-center"> |
| 68 | + <div className="text-accent-50 mb-12 w-full"> |
| 69 | + <h2 className="text-2xl font-semibold">Preview</h2> |
| 70 | + <h3 className="text-accent-400">{previewIds.length} theme(s) selected</h3> |
| 71 | + </div> |
| 72 | + <ChatBot |
| 73 | + flow={flow} |
| 74 | + themes={previewIds.map((themeId) => ({ id: themeId }))} |
| 75 | + settings={{ general: { embedded: true } }} |
| 76 | + styles={{ chatWindowStyle: { height: '50vh' } }} |
| 77 | + /> |
| 78 | + <div className="w-full mt-8"> |
| 79 | + {previewIds.map((previewId) => { |
| 80 | + const previewTitle = formatPreviewIdToTitleCase(previewId) |
| 81 | + return <div className="flex justify-between my-2"> |
| 82 | + <span className="text-accent-50 font-semibold text-lg">{previewTitle}</span> |
| 83 | + <span className="text-blue-500 font-semibold">Remove Selection (x)</span> |
| 84 | + </div> |
| 85 | + })} |
| 86 | + </div> |
| 87 | + <div className="flex flex-col p-3 w-full items-center"> |
| 88 | + <button className="bg-accent-700 text-accent-400 text-lg py-2 rounded-lg my-2 w-[90%] hover:bg-accent-600 hover:text-accent-300">Download theme bundle</button> |
| 89 | + <button className="bg-accent-300 text-accent-950 text-lg py-2 rounded-lg my-2 w-[90%] hover:bg-accent-200">Edit in theme builder</button> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + ); |
| 93 | +}; |
| 94 | + |
| 95 | +export default DesktopThemePreview; |
0 commit comments