diff --git a/src/app/(app)/page.tsx b/src/app/(app)/page.tsx
index 319d990..4abece8 100644
--- a/src/app/(app)/page.tsx
+++ b/src/app/(app)/page.tsx
@@ -9,12 +9,6 @@ export default async function App() {
-
-
)
}
diff --git a/src/app/(app)/vision-ai/components/channels-manager/components/channels-table.tsx b/src/app/(app)/vision-ai/components/channels-manager/components/channels-table.tsx
index 9065b07..29b31c3 100644
--- a/src/app/(app)/vision-ai/components/channels-manager/components/channels-table.tsx
+++ b/src/app/(app)/vision-ai/components/channels-manager/components/channels-table.tsx
@@ -31,6 +31,7 @@ import { deleteNotificationChannel } from '@/http/notification-channel/delete-no
import { updateNotificationChannel } from '@/http/notification-channel/update-notification-channel'
import { queryClient } from '@/lib/react-query'
import { cn } from '@/lib/utils'
+import type { NotificationChannel } from '@/models/entities'
export function ChannelsTable() {
const { data: channels } = useNotificationChannels()
@@ -51,11 +52,18 @@ export function ChannelsTable() {
setIsLoading(true)
createNotificationChannel(name)
- .then(() => {
- queryClient.invalidateQueries({
- queryKey: ['notification-channels'],
- })
+ .then((newChannel) => {
setChannelName('')
+ const cached = queryClient.getQueryData([
+ 'notification-channels',
+ ])
+
+ if (!cached) return
+
+ queryClient.setQueryData(
+ ['notification-channels'],
+ [...cached, newChannel],
+ )
})
.catch(() => {
toast.error('Erro ao criar canal. Tente novamente.')
@@ -74,11 +82,23 @@ export function ChannelsTable() {
setIsLoading(true)
updateNotificationChannel(id, name)
- .then(() => {
- setChannelName('')
- queryClient.invalidateQueries({
- queryKey: ['notification-channels'],
- })
+ .then((updatedChannel) => {
+ const cached = queryClient.getQueryData([
+ 'notification-channels',
+ ])
+
+ if (!cached) return
+
+ queryClient.setQueryData(
+ ['notification-channels'],
+ cached.map((cachedChannel) =>
+ cachedChannel.id === updatedChannel.id
+ ? updatedChannel
+ : cachedChannel,
+ ),
+ )
+
+ setEdittingChannel(null)
})
.catch(() => {
toast.error('Erro ao editar canal. Tente novamente.')
@@ -93,10 +113,17 @@ export function ChannelsTable() {
setIsLoading(true)
await deleteNotificationChannel(id)
.then(() => {
- queryClient.invalidateQueries({
- queryKey: ['notification-channels'],
- })
setIsDeleteAlertOpen(false)
+ const cached = queryClient.getQueryData([
+ 'notification-channels',
+ ])
+
+ if (!cached) return
+
+ queryClient.setQueryData(
+ ['notification-channels'],
+ cached.filter((cachedChannel) => cachedChannel.id !== id),
+ )
})
.catch(() => {
toast.error('Erro ao excluir canal. Tente novamente.')
@@ -225,13 +252,16 @@ export function ChannelsTable() {
}
className={cn(
'relative',
- isLoading && 'text-destructive',
+ isLoading &&
+ 'text-destructive flex items-center justify-center',
)}
disabled={isLoading}
>
Continuar
{isLoading && (
-
+
+
+
)}
diff --git a/src/app/(app)/vision-ai/project/[id]/actions.ts b/src/app/(app)/vision-ai/project/[id]/actions.ts
deleted file mode 100644
index 80d8cad..0000000
--- a/src/app/(app)/vision-ai/project/[id]/actions.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-'use server'
-
-import {} from 'date-fns'
-import { cookies } from 'next/headers'
-import { redirect } from 'next/navigation'
-
-import { env } from '@/env'
-
-interface UpdateProject {
- id: string
- name: string
- model: string
- model_config: {
- yolo_default_precision?: number
- yolo_send_message?: boolean
- yolo_crowd_count?: number
- }
- cameras_id: string[]
- time_start?: string
- time_end?: string
- discord_id: string
- enable: boolean
-}
-
-export async function updateProjectAction(props: UpdateProject) {
- const cookieStore = await cookies()
- const token = cookieStore.get('token')?.value
- await fetch(`${env.VISION_AI_API_URL}/project/${props.id}`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- },
- body: JSON.stringify({
- name: props.name,
- model: props.model,
- model_config: props.model_config,
- cameras_id: props.cameras_id,
- time_start: props.time_start,
- time_end: props.time_end,
- discord_id: props.discord_id,
- enable: props.enable,
- }),
- })
-
- redirect('/vision-ai')
-}
-
-export async function formatCurrentDateTime(time: string) {
- const today = new Date()
-
- const utcTodayWithTimeStr = `${today.toISOString().split('T')[0]}T${time}`
-
- const newDate = new Date(utcTodayWithTimeStr)
-
- return newDate
-}
diff --git a/src/app/(app)/vision-ai/project/[id]/page.tsx b/src/app/(app)/vision-ai/project/[id]/page.tsx
index 3bfc4c2..4495424 100644
--- a/src/app/(app)/vision-ai/project/[id]/page.tsx
+++ b/src/app/(app)/vision-ai/project/[id]/page.tsx
@@ -97,9 +97,6 @@ export default function ProjectDetails() {
resolver: zodResolver(projectFormSchema),
})
- console.log('model', watch('model'))
- console.log('notificationChannelId', watch('notificationChannelId'))
-
useEffect(() => {
async function handleRedirect() {
await setToastDataCookie({
@@ -111,7 +108,6 @@ export default function ProjectDetails() {
}
if (project && channels && cameras) {
- console.log('project', project)
const channel = channels.find(
(channel) => channel.id === project.discord_id,
)