|
| 1 | +import React, { Fragment, useState } from 'react'; |
| 2 | +import { PropTypes } from 'prop-types'; |
| 3 | +import { Dialog, Transition, Listbox } from '@headlessui/react'; |
| 4 | +import Button from 'components/atoms/common/Button'; |
| 5 | +import { BUTTON_TYPES } from 'constants/Common'; |
| 6 | +import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/20/solid'; |
| 7 | +import { Square3Stack3DIcon } from '@heroicons/react/24/outline'; |
| 8 | + |
| 9 | +const GenerateFlowTestModal = ({ closeFn = () => null, open = false }) => { |
| 10 | + const [selectedModel, setSelectedModel] = useState(null); |
| 11 | + const [textareaValue, setTextareaValue] = useState(''); |
| 12 | + |
| 13 | + return ( |
| 14 | + <Transition appear show={open} as={Fragment}> |
| 15 | + <Dialog as='div' className='relative z-10' onClose={closeFn}> |
| 16 | + <Transition.Child |
| 17 | + as={Fragment} |
| 18 | + enter='ease-out duration-300' |
| 19 | + enterFrom='opacity-0' |
| 20 | + enterTo='opacity-100' |
| 21 | + leave='ease-in duration-200' |
| 22 | + leaveFrom='opacity-100' |
| 23 | + leaveTo='opacity-0' |
| 24 | + > |
| 25 | + <div className='fixed inset-0 bg-black/25' /> |
| 26 | + </Transition.Child> |
| 27 | + |
| 28 | + <div className='fixed inset-0 overflow-y-auto'> |
| 29 | + <div className='flex min-h-full items-center justify-center p-4 text-center'> |
| 30 | + <Transition.Child |
| 31 | + as={Fragment} |
| 32 | + enter='ease-out duration-300' |
| 33 | + enterFrom='opacity-0 scale-95' |
| 34 | + enterTo='opacity-100 scale-100' |
| 35 | + leave='ease-in duration-200' |
| 36 | + leaveFrom='opacity-100 scale-100' |
| 37 | + leaveTo='opacity-0 scale-95' |
| 38 | + > |
| 39 | + <Dialog.Panel className='w-full max-w-md transform overflow-hidden rounded-2xl bg-white p-6 text-left align-middle shadow-xl transition-all'> |
| 40 | + <Dialog.Title |
| 41 | + as='h3' |
| 42 | + className='border-b border-neutral-300 pb-4 text-center text-lg font-semibold text-gray-900' |
| 43 | + > |
| 44 | + Use our AI to generate the flowtest |
| 45 | + </Dialog.Title> |
| 46 | + <div className='mt-6'> |
| 47 | + <Listbox value={selectedModel} onChange={setSelectedModel}> |
| 48 | + <div className='relative flex h-full w-full'> |
| 49 | + <Listbox.Button className='flex w-full cursor-default items-center justify-between gap-4 rounded border border-neutral-300 py-4'> |
| 50 | + <div className='min-w-32 pl-2 text-left'>{selectedModel ? selectedModel : 'Select model'}</div> |
| 51 | + <ChevronUpDownIcon className='h-5 w-5' aria-hidden='true' /> |
| 52 | + </Listbox.Button> |
| 53 | + <Transition |
| 54 | + as={Fragment} |
| 55 | + leave='transition ease-in duration-100' |
| 56 | + leaveFrom='opacity-100' |
| 57 | + leaveTo='opacity-0' |
| 58 | + > |
| 59 | + <Listbox.Options className='absolute right-0 top-6 z-10 mt-1 max-h-60 w-full overflow-auto rounded bg-white py-1 text-base shadow-lg ring-1 ring-black/5'> |
| 60 | + <Listbox.Option |
| 61 | + className={({ active }) => |
| 62 | + `relative cursor-default select-none py-2 pl-10 pr-4 ${ |
| 63 | + active ? 'bg-amber-100 text-amber-900' : 'text-gray-900' |
| 64 | + }` |
| 65 | + } |
| 66 | + value={'Model 1'} |
| 67 | + > |
| 68 | + {({ selected }) => ( |
| 69 | + <> |
| 70 | + <span className={`block truncate ${selected ? 'font-medium' : 'font-normal'}`}> |
| 71 | + Model 1 |
| 72 | + </span> |
| 73 | + {selected ? ( |
| 74 | + <span className='absolute inset-y-0 left-0 flex items-center pl-3 text-amber-600'> |
| 75 | + <CheckIcon className='h-5 w-5' aria-hidden='true' /> |
| 76 | + </span> |
| 77 | + ) : null} |
| 78 | + </> |
| 79 | + )} |
| 80 | + </Listbox.Option> |
| 81 | + <Listbox.Option |
| 82 | + className={({ active }) => |
| 83 | + `relative cursor-default select-none py-2 pl-10 pr-4 ${ |
| 84 | + active ? 'bg-amber-100 text-amber-900' : 'text-gray-900' |
| 85 | + }` |
| 86 | + } |
| 87 | + value={'Model 2'} |
| 88 | + > |
| 89 | + {({ selected }) => ( |
| 90 | + <> |
| 91 | + <span className={`block truncate ${selected ? 'font-medium' : 'font-normal'}`}> |
| 92 | + Model 2 |
| 93 | + </span> |
| 94 | + {selected ? ( |
| 95 | + <span className='absolute inset-y-0 left-0 flex items-center pl-3 text-amber-600'> |
| 96 | + <CheckIcon className='h-5 w-5' aria-hidden='true' /> |
| 97 | + </span> |
| 98 | + ) : null} |
| 99 | + </> |
| 100 | + )} |
| 101 | + </Listbox.Option> |
| 102 | + </Listbox.Options> |
| 103 | + </Transition> |
| 104 | + </div> |
| 105 | + </Listbox> |
| 106 | + <div className='mt-4'> |
| 107 | + <textarea |
| 108 | + id='gen-ai-text' |
| 109 | + className='block w-full rounded border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 outline-blue-300 focus:border-blue-100 focus:ring-blue-100' |
| 110 | + placeholder='Text' |
| 111 | + onChange={(event) => setTextareaValue(event.target.value)} |
| 112 | + /> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + <div className='mt-6 flex items-center gap-2'> |
| 116 | + <Button btnType={BUTTON_TYPES.error} isDisabled={false} onClickHandle={closeFn} fullWidth={true}> |
| 117 | + Cancel |
| 118 | + </Button> |
| 119 | + <Button |
| 120 | + btnType={BUTTON_TYPES.info} |
| 121 | + isDisabled={false} |
| 122 | + fullWidth={true} |
| 123 | + onClickHandle={() => { |
| 124 | + console.log(`\n Model selected : ${selectedModel} \n`); |
| 125 | + console.log(`\n Model Text : ${textareaValue} \n`); |
| 126 | + }} |
| 127 | + > |
| 128 | + Generate |
| 129 | + </Button> |
| 130 | + </div> |
| 131 | + </Dialog.Panel> |
| 132 | + </Transition.Child> |
| 133 | + </div> |
| 134 | + </div> |
| 135 | + </Dialog> |
| 136 | + </Transition> |
| 137 | + ); |
| 138 | +}; |
| 139 | + |
| 140 | +GenerateFlowTestModal.propTypes = { |
| 141 | + closeFn: PropTypes.func.isRequired, |
| 142 | + open: PropTypes.boolean.isRequired, |
| 143 | +}; |
| 144 | +export default GenerateFlowTestModal; |
0 commit comments