import React, {useState} from 'react' import {motion} from "framer-motion"; import {Badge} from "@/components/ui/badge" import {Link} from '@mui/material'; import {Tabs, TabsContent} from "@/components/ui/tabs" import {Button} from "@/components/ui/button" import { BodyOfferwallSoftpairPostProductIdOfferwall37d1da64OfferwallIdPost, BucketTask, OfferwallApi, SoftPairBucket, UserQuestionAnswerIn } from "@/api" import {ColumnDef, flexRender, getCoreRowModel, useReactTable,} from "@tanstack/react-table" import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow,} from "@/components/ui/table" import {useSelector} from "react-redux"; import {Switch} from "@/components/ui/switch" import {Card, CardContent, CardFooter} from "@/components/ui/card.tsx"; import {makeSelectQuestionsByIds} from "@/models/questionSlice.ts" import {CheckIcon, MessageCircleQuestionIcon, XIcon} from "lucide-react" import {useAppDispatch, useAppSelector} from '@/hooks' import {Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger,} from "@/components/ui/sheet" import {ProfileQuestionFull} from "@/pages/Questions.tsx" import {Answer, selectAnswerForQuestion, submitAnswer} from "@/models/answerSlice.ts"; import {assert, formatCentsToUSD, formatSeconds} from "@/lib/utils.ts"; import {setAvailabilityCount, setOfferwallId} from "@/models/appSlice.ts"; import {setBuckets} from "@/models/bucketSlice.ts"; interface DataTableProps { columns: ColumnDef[] data: TData[] } const BucketStatus: React.FC = ({bucket}) => { switch (bucket.eligibility) { case "unconditional": return < CheckIcon xlinkTitle="you are good" />; case "conditional": return ; case "ineligible": return ; } } const ContentsGrid: React.FC = ({bucket}) => { const columns: ColumnDef[] = [ { accessorKey: "loi", header: "Length", cell: ({getValue}) => formatSeconds(getValue() as number), }, { accessorKey: "payout", header: "Payout", cell: ({getValue}) => formatCentsToUSD(getValue() as number) }, ] const data: BucketTask[] = bucket.contents const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), }) return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} ) })} ))} { table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) }
) } const ConditionalQuestions: React.FC = ({bucket}) => { const dispatch = useAppDispatch() const questions = useSelector(makeSelectQuestionsByIds(bucket.missing_questions)) const question = questions[0] const answer: Answer | undefined = useSelector(selectAnswerForQuestion(question)); const app = useAppSelector(state => state.app) console.log("Conditional bucket:", questions, question, answer) const [open, setOpen] = useState(false) const submitEvt = () => { dispatch(submitAnswer({question: question})) assert(!answer?.complete, "Can't submit completed Answer") assert(!answer?.processing, "Can't submit processing Answer") assert(answer?.error_msg.length == 0, "Can't submit Answer with error message") let body: BodyOfferwallSoftpairPostProductIdOfferwall37d1da64OfferwallIdPost = { 'answers': [{ "question_id": question.question_id, "answer": answer.values } as UserQuestionAnswerIn ] } new OfferwallApi().offerwallSoftpairPostProductIdOfferwall37d1da64OfferwallIdPost(app.bpid, app.offerwall_id, app.bpuid, body) .then(res => { if (res.status == 200) { dispatch(setAvailabilityCount(res.data.offerwall.availability_count)) dispatch(setOfferwallId(res.data.offerwall.id)) dispatch(setBuckets(res.data.offerwall.buckets)) } else { // let error_msg = res.data.msg } }) .catch(err => console.log(err)); } return ( <> Bucket Questions This survey has some unanswered questions. Answer these to determine if you're eligible for the Survey Bucket { questions.map(q => { return }) } ) } const CallToAction: React.FC = ({bucket}) => { switch (bucket.eligibility) { case "unconditional": return (
) case "conditional": return (
) case "ineligible": return (
) } } const ConditionalBucket: React.FC = ({bucket}) => { const [tab, setTab] = useState("bucket_cta") const toggleTab = () => setTab(tab === "bucket_cta" ? "bucket_details" : "bucket_cta") return ( {bucket.contents.length.toLocaleString()}
{formatCentsToUSD(bucket.payout)} {formatSeconds(bucket.loi)} {/**/} {/*4.5*/} {/**/} {/* */} {/**/}
) } const Offerwall = () => { const buckets = useAppSelector(state => state.buckets) return (
{buckets.map((bucket) => ( ))}
) } export { Offerwall }