From a5ae285d03f453b47096a0632dd3a9c4c4f6e868 Mon Sep 17 00:00:00 2001 From: Nudesuppe42 Date: Sat, 10 Aug 2024 18:45:01 +0200 Subject: [PATCH] feat(admin): :sparkles: Option to check an image --- src/pages/admin/images/index.tsx | 63 ++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/pages/admin/images/index.tsx b/src/pages/admin/images/index.tsx index 59e6cb0a..0f6110e7 100644 --- a/src/pages/admin/images/index.tsx +++ b/src/pages/admin/images/index.tsx @@ -8,18 +8,19 @@ import { Pagination, Table, Text, + Tooltip, rem, } from '@mantine/core'; -import { IconExternalLink, IconTrash } from '@tabler/icons-react'; import { showNotification, updateNotification } from '@mantine/notifications'; +import { IconCheck, IconExternalLink, IconTrash } from '@tabler/icons-react'; import useSWR, { mutate } from 'swr'; -import Link from 'next/link'; import Page from '@/components/Page'; +import { useAccessToken } from '@/hooks/useAccessToken'; +import thumbnail from '@/public/images/thumbnails/teams.png'; import { modals } from '@mantine/modals'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; -import thumbnail from '@/public/images/thumbnails/teams.png'; -import { useAccessToken } from '@/hooks/useAccessToken'; +import Link from 'next/link'; import { useState } from 'react'; var vagueTime = require('vague-time'); @@ -93,6 +94,49 @@ const Settings = () => { }, }); }; + const handleCheckImage = (image: any) => { + setLoading(true); + const notification = showNotification({ + title: 'Checking Claim Image', + message: 'Please wait for this to finish before checking other images.', + loading: true, + autoClose: false, + withCloseButton: false, + }); + fetch(process.env.NEXT_PUBLIC_API_URL + `/admin/images/${image.id}/check`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + accessToken, + }, + }) + .then((res) => res.json()) + .then((res) => { + if (res.errors) { + updateNotification({ + id: notification, + title: 'Check failed', + loading: false, + message: res.error, + color: 'red', + withCloseButton: true, + }); + setLoading(false); + } else { + updateNotification({ + id: notification, + title: 'Image checked', + message: 'All Data has been saved', + color: 'green', + loading: false, + autoClose: 5000, + withCloseButton: true, + }); + setLoading(false); + mutate(`/claims/images?take=20&skip=${activePage * 20 - 20}`); + } + }); + }; return ( { vagueTime.get({ to: new Date(image.createdAt) })} + + handleCheckImage(image)} + loading={loading} + disabled={loading} + > + + +