@@ -12,12 +12,15 @@ import {
1212 getAnalyticsConfig ,
1313 updateAnalyticsConfig ,
1414} from "@/lib/settings" ;
15+ import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
1516import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
17+ import { ChartColumn , CircleX } from "lucide-react" ;
1618import { useState } from "react" ;
1719import { toast } from "sonner" ;
1820import { useReadOnlyMode } from "../providers/SessionProvider" ;
1921import { BaseTable } from "../baseTable" ;
2022import AddAnalyticsConfigForm from "../forms/AddAnalyticsConfigForm" ;
23+ import { Alert } from "../ui/alert" ;
2124import { Button } from "../ui/button" ;
2225import { DialogFooter , DialogHeader } from "../ui/dialog" ;
2326import { analyticsConfigColumns } from "./columns" ;
@@ -48,14 +51,7 @@ export function AnalyticsConfigTable({ projectId }: AnalyticsConfigTableProps) {
4851 }
4952
5053 const deleteAnalyticsConfigHandler = useMutation ( {
51- mutationFn : ( ) => {
52- const deletePromises = selectedRows . map ( async ( row ) => {
53- const projectId = row . id ;
54- return deleteAnalyticsConfig ( projectId ) ;
55- } ) ;
56-
57- return Promise . all ( deletePromises ) ;
58- } ,
54+ mutationFn : async ( ) => deleteAnalyticsConfig ( projectId ) ,
5955 onSuccess : ( ) => {
6056 toast . success ( "Success" , {
6157 description : `Successfully deleted analytics configs.` ,
@@ -163,48 +159,82 @@ export function AnalyticsConfigTable({ projectId }: AnalyticsConfigTableProps) {
163159 </ DialogContent >
164160 </ Dialog >
165161 < h1 className = "text-lg font-bold" > Analytics Configurations</ h1 >
166- < BaseTable
167- data = { analyticsConfigRowData }
168- columns = { analyticsConfigColumns (
169- Number ( projectId ) ,
170- addAnalyticsConfigHandler . isPending ,
171- (
172- projectId : number ,
173- keys : {
174- serverAnalyticsKey : string ;
175- clientAnalyticsKey : string ;
162+ { isError && (
163+ < Alert className = "border-red-500/20 bg-red-500/10" >
164+ < div className = "flex items-center gap-2 text-red-400" >
165+ < CircleX className = "h-4 w-4" />
166+ < span className = "text-sm" >
167+ Couldn't load analytics config: { error . message }
168+ </ span >
169+ </ div >
170+ </ Alert >
171+ ) }
172+ { isError ? null : ! isLoading && analyticsConfigRowData . length === 0 ? (
173+ < Card className = "max-w-[35%]" >
174+ < CardHeader >
175+ < div className = "flex items-center gap-3" >
176+ < ChartColumn className = "h-5 w-5 text-muted-foreground" />
177+ < CardTitle > No Analytics Configuration</ CardTitle >
178+ </ div >
179+ </ CardHeader >
180+ < CardContent >
181+ < p className = "text-sm text-muted-foreground mb-4" >
182+ Project { projectId } has no analytics configuration yet. Add a
183+ server key and a client key to start tracking user interactions,
184+ visits, clicks, and custom events using Juno.
185+ </ p >
186+ < Button
187+ onClick = { ( ) => setIsAddConfigDialogOpen ( true ) }
188+ disabled = { isReadOnly || addAnalyticsConfigHandler . isPending }
189+ >
190+ Set up analytics
191+ </ Button >
192+ </ CardContent >
193+ </ Card >
194+ ) : (
195+ < BaseTable
196+ data = { analyticsConfigRowData }
197+ columns = { analyticsConfigColumns (
198+ Number ( projectId ) ,
199+ addAnalyticsConfigHandler . isPending ,
200+ (
201+ projectId : number ,
202+ keys : {
203+ serverAnalyticsKey : string ;
204+ clientAnalyticsKey : string ;
205+ } ,
206+ ) => {
207+ const { serverAnalyticsKey, clientAnalyticsKey } = keys ;
208+ updateAnalyticsConfigHandler . mutate ( {
209+ projectId,
210+ serverAnalyticsKey,
211+ clientAnalyticsKey,
212+ } ) ;
213+ setIsAddConfigDialogOpen ( false ) ;
176214 } ,
177- ) => {
178- const { serverAnalyticsKey, clientAnalyticsKey } = keys ;
179- updateAnalyticsConfigHandler . mutate ( {
180- projectId,
181- serverAnalyticsKey,
182- clientAnalyticsKey,
183- } ) ;
184- setIsAddConfigDialogOpen ( false ) ;
185- } ,
186- isReadOnly ,
187- ) }
188- isLoading = { isLoading }
189- filterParams = { {
190- placeholder : "Filter by environment..." ,
191- filterColumn : "environment" ,
192- } }
193- onAddNewRow = { ( ) => {
194- if ( analyticsConfigRowData . length === 0 ) {
195- setIsAddConfigDialogOpen ( true ) ;
196- } else {
197- toast . error ( "Error" , {
198- description :
199- "Project can have at most 1 analytics configuration per environment" ,
200- } ) ;
201- }
202- } }
203- onDeleteRow = { ( rows ) => {
204- setSelectedRows ( rows ) ;
205- setIsDeleteDialogOpen ( true ) ;
206- } }
207- />
215+ isReadOnly ,
216+ ) }
217+ isLoading = { isLoading }
218+ filterParams = { {
219+ placeholder : "Filter by environment..." ,
220+ filterColumn : "environment" ,
221+ } }
222+ onAddNewRow = { ( ) => {
223+ if ( analyticsConfigRowData . length === 0 ) {
224+ setIsAddConfigDialogOpen ( true ) ;
225+ } else {
226+ toast . error ( "Error" , {
227+ description :
228+ "Project can have at most 1 analytics configuration per environment" ,
229+ } ) ;
230+ }
231+ } }
232+ onDeleteRow = { ( rows ) => {
233+ setSelectedRows ( rows ) ;
234+ setIsDeleteDialogOpen ( true ) ;
235+ } }
236+ />
237+ ) }
208238 </ div >
209239 ) ;
210240}
0 commit comments