MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / DashboardCost

Function DashboardCost

pages/usage.tsx:215–254  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

213}
214
215function DashboardCost() {
216 // It's getting WET in here
217 const supabase = useSupabaseClient<Database>();
218 const { profile, refreshProfile } = useProfile();
219 const [cost, setCost] = useState([{}] as { date: string; value: number }[]);
220 const [sum, setSum] = useState(0);
221 const [loading, setLoading] = useState(true);
222
223 useEffect(() => {
224 if (!profile) return;
225 (async () => {
226 const res = await supabase
227 .from("usage")
228 .select("*")
229 .eq("org_id", profile?.org_id!);
230 if (res.error) throw res.error;
231 setCost(res.data.map((d) => ({ date: d.date, value: d.usage })));
232 setSum(res.data.reduce((acc, curr) => acc + curr.usage, 0));
233 setLoading(false);
234 })();
235 }, [profile, refreshProfile, supabase]);
236 return (
237 <div className="bg-gray-800 min-h-screen">
238 <Navbar current={"Usage"} />
239 <div className="h-[calc(100%-4rem)] flex flex-col gap-y-4 mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 bg-gray-800 pb-8 place-items-center">
240 <div className="mt-8 bg-gray-850 rounded-md px-6 py-4 overflow-visible max-w-7xl w-full">
241 <div className="place-items-center m-auto text-center">
242 <h1 className="text-2xl text-gray-100">OpenAI API usage </h1>
243 <p className="text-gray-200 mt-2 text-xl font-bold text-purple-500">
244 {`Total Cost $${Math.round(sum * 100) / 100}`}
245 </p>
246 </div>
247 <div className="max-w-5xl mx-auto">
248 {!loading && <DatesBarGraph data={cost} ylabel="Cost (USD)" />}
249 </div>
250 </div>
251 </div>
252 </div>
253 );
254}
255
256export const getServerSideProps = pageGetServerSideProps;

Callers

nothing calls this directly

Calls 1

useProfileFunction · 0.90

Tested by

no test coverage detected