| 1 | import { ExclamationCircleIcon } from "@heroicons/react/24/outline"; |
| 2 | import { useDispatch } from "react-redux"; |
| 3 | import { useNavigate } from "react-router-dom"; |
| 4 | import { AddModelForm } from "../../forms/AddModelForm"; |
| 5 | import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; |
| 6 | import { FREE_TRIAL_LIMIT_REQUESTS } from "../../util/freeTrial"; |
| 7 | import { ToolTip } from "../gui/Tooltip"; |
| 8 | |
| 9 | interface FreeTrialProgressBarProps { |
| 10 | completed: number; |
| 11 | total: number; |
| 12 | } |
| 13 | |
| 14 | function FreeTrialProgressBar({ completed, total }: FreeTrialProgressBarProps) { |
| 15 | const dispatch = useDispatch(); |
| 16 | const navigate = useNavigate(); |
| 17 | const fillPercentage = Math.min(100, Math.max(0, (completed / total) * 100)); |
| 18 | |
| 19 | function onClick() { |
| 20 | dispatch(setShowDialog(true)); |
| 21 | dispatch( |
| 22 | setDialogMessage( |
| 23 | <AddModelForm |
| 24 | onDone={() => { |
| 25 | dispatch(setShowDialog(false)); |
| 26 | navigate("/"); |
| 27 | }} |
| 28 | />, |
| 29 | ), |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | if (completed > total) { |
| 34 | return ( |
| 35 | <ToolTip |
| 36 | place="top" |
| 37 | content="Configure a model above in order to continue" |
| 38 | > |
| 39 | <div className="flex flex-1 cursor-default select-none items-center justify-center gap-1"> |
| 40 | <ExclamationCircleIcon width="18px" height="18px" color="red" /> |
| 41 | Trial limit reached |
| 42 | </div> |
| 43 | </ToolTip> |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | return ( |
| 48 | <ToolTip |
| 49 | place="top" |
| 50 | content={`Click to use your own API key or local LLM (required after ${FREE_TRIAL_LIMIT_REQUESTS} inputs)`} |
| 51 | > |
| 52 | <div |
| 53 | className="flex flex-1 cursor-pointer flex-row items-center gap-2 text-[10px] text-gray-400 sm:gap-3" |
| 54 | onClick={onClick} |
| 55 | > |
| 56 | <span> |
| 57 | Free trial <span className="hidden sm:inline">requests</span> |
| 58 | </span> |
| 59 | <div className="flex h-1.5 flex-1 rounded-md border border-solid border-gray-400"> |
| 60 | <div |
| 61 | className={`h-full rounded-lg transition-all duration-200 ease-in-out ${ |
| 62 | completed / total > 0.75 ? "bg-amber-500" : "bg-stone-500" |
| 63 | }`} |
| 64 | style={{ |
| 65 | width: `${fillPercentage}%`, |
| 66 | }} |
| 67 | /> |
| 68 | </div> |
| 69 | <span> |
| 70 | {completed} / {total} |
| 71 | </span> |
| 72 | </div> |
| 73 | </ToolTip> |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | export default FreeTrialProgressBar; |