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

Function DashboardNumMessages

pages/usage.tsx:132–213  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

130}
131
132function DashboardNumMessages() {
133 const supabase = useSupabaseClient<Database>();
134 const { profile, refreshProfile } = useProfile();
135 const [queriesTimeseries, setQueriesTimeseries] = useState([{}] as {
136 date: string;
137 value: number;
138 }[]);
139 const [totalThisMonth, setTotalThisMonth] = useState(0);
140 const [totalLastMonth, setTotalLastMonth] = useState(0);
141 const [loading, setLoading] = useState(true);
142
143 const today = new Date();
144 const firstOfThisMonth = new Date(today.getFullYear(), today.getMonth(), 1);
145 const startOfPreviousMonth = new Date(
146 today.getFullYear(),
147 today.getMonth() - 1,
148 1,
149 );
150 const endOfPreviousMonth = new Date(today.getFullYear(), today.getMonth(), 0);
151
152 useEffect(() => {
153 if (!profile) return;
154 (async () => {
155 const thisMonthRes = await supabase
156 .from("usage")
157 .select("*")
158 .eq("org_id", profile?.org_id!)
159 .gte("date", firstOfThisMonth.toISOString());
160 if (thisMonthRes.error) throw thisMonthRes.error;
161
162 setQueriesTimeseries(
163 thisMonthRes.data.map((d) => ({
164 date: d.date,
165 value: d.num_user_queries,
166 })),
167 );
168 setTotalThisMonth(
169 thisMonthRes.data.reduce((acc, curr) => acc + curr.num_user_queries, 0),
170 );
171
172 const lastMonthRes = await supabase
173 .from("usage")
174 .select("*")
175 .eq("org_id", profile?.org_id!)
176 .gte("date", startOfPreviousMonth.toISOString())
177 .lte("date", endOfPreviousMonth.toISOString());
178
179 if (lastMonthRes.error) throw thisMonthRes.error;
180 setTotalLastMonth(
181 lastMonthRes.data.reduce((acc, curr) => acc + curr.num_user_queries, 0),
182 );
183
184 setLoading(false);
185 })();
186 }, [profile, refreshProfile, supabase]);
187 return (
188 <div className="bg-gray-800 min-h-screen">
189 <Navbar current={"Usage"} />

Callers

nothing calls this directly

Calls 1

useProfileFunction · 0.90

Tested by

no test coverage detected