diff --git a/src/api/feedApi.ts b/src/api/feedApi.ts index 717d5c6..759462e 100644 --- a/src/api/feedApi.ts +++ b/src/api/feedApi.ts @@ -62,6 +62,20 @@ class FeedApi { throw err; } } + + static async deletePost(id: number) { + try { + const resp = await axios.delete(`${URL}${id}`, { + headers: { + Authorization: getAuthHeader(), + }, + }); + return resp.data; + } catch (err) { + console.error(err); + throw err; + } + } } export default FeedApi; diff --git a/src/api/jobAdApi.ts b/src/api/jobAdApi.ts index c28c5a0..a26c28d 100644 --- a/src/api/jobAdApi.ts +++ b/src/api/jobAdApi.ts @@ -72,6 +72,20 @@ class JobAdApi { throw err; } } + + static async deleteJobAd(id: number) { + try { + const resp = await axios.delete(`${URL}${id}`, { + headers: { + Authorization: getAuthHeader(), + }, + }); + return resp.data; + } catch (err) { + console.error(err); + throw err; + } + } } export default JobAdApi; diff --git a/src/pages/admin/events/index.tsx b/src/pages/admin/events/index.tsx index 80f1081..edfc3f4 100644 --- a/src/pages/admin/events/index.tsx +++ b/src/pages/admin/events/index.tsx @@ -14,6 +14,10 @@ const URL = "/admin/events"; const StyledButton = styled(Button) <{ $colorOverride: "red" }>` background-color: ${(p) => p.$colorOverride}; + border-radius: 8px; + color: white; + font-size: 13px; + font-weight: bold; `; const confirmDelete = async (event: Event) => { diff --git a/src/pages/admin/feed/index.tsx b/src/pages/admin/feed/index.tsx index 757ed1e..793f27b 100644 --- a/src/pages/admin/feed/index.tsx +++ b/src/pages/admin/feed/index.tsx @@ -1,14 +1,37 @@ import React from "react"; import { NextPage } from "next"; import { formatRelative } from "date-fns"; +import { toast } from "react-toastify"; +import styled from "styled-components"; import AdminListCommon from "@views/admin/AdminListCommon"; -import { Link } from "@components/index"; +import { Button, Link } from "@components/index"; import AddLink from "@components/AddLink"; import Post from "@models/Feed"; +import PostApi from "@api/feedApi"; import useFetchFeed from "@hooks/useFetchFeed"; const URL = "/admin/feed"; +const StyledButton = styled(Button) <{ $colorOverride: "red" }>` + background-color: ${(p) => p.$colorOverride}; + border-radius: 8px; + color: white; + font-size: 13px; + font-weight: bold; +`; + +const confirmDelete = async (post: Post) => { + if (window.confirm(`Delete: ${post.id}: ${post.title_fi}/${post.title_en}; Are you sure?`) === true) { + try { + await PostApi.deletePost(post.id); + toast.success("Post removed successfully 😎"); + window.location.reload(); // TODO: Fetch/update post list, so user sees the signup in the list + } catch (err) { + toast.error("Uh oh! Something went wrong! Try again later. 😟"); + } + } +}; + const renderData = (feed: Post[]) => { if (!feed || feed.length === 0) { return
No posts.
; @@ -29,6 +52,11 @@ const renderData = (feed: Post[]) => { {post.title_fi} {post.description_fi} {formatRelative(new Date(post.publish_time), new Date())} + + confirmDelete(post)}> + Delete + + ))} diff --git a/src/pages/admin/jobads/index.tsx b/src/pages/admin/jobads/index.tsx index 9500a38..a2dd6a6 100644 --- a/src/pages/admin/jobads/index.tsx +++ b/src/pages/admin/jobads/index.tsx @@ -1,14 +1,37 @@ import React from "react"; import { NextPage } from "next"; import { formatRelative } from "date-fns"; +import { toast } from "react-toastify"; +import styled from "styled-components"; import AdminListCommon from "@views/admin/AdminListCommon"; -import { Link } from "@components/index"; +import { Button, Link } from "@components/index"; import AddLink from "@components/AddLink"; import JobAd from "@models/JobAd"; import useFetchJobAds from "@hooks/useFetchJobAds"; +import JobAdApi from "@api/jobAdApi"; const URL = "/admin/jobads"; +const StyledButton = styled(Button) <{ $colorOverride: "red" }>` + background-color: ${(p) => p.$colorOverride}; + border-radius: 8px; + color: white; + font-size: 13px; + font-weight: bold; +`; + +const confirmDelete = async (jobad: JobAd) => { + if (window.confirm(`Delete: ${jobad.id}: ${jobad.title_fi}/${jobad.title_en}; Are you sure?`) === true) { + try { + await JobAdApi.deleteJobAd(jobad.id); + toast.success("Signup removed successfully 😎"); + window.location.reload(); // TODO: Fetch/update event list, so user sees the signup in the list + } catch (err) { + toast.error("Uh oh! Something went wrong! Try again later. 😟"); + } + } +}; + const renderData = (jobAds: JobAd[]) => { if (!jobAds || jobAds.length === 0) { return
No advertisements.
; @@ -33,6 +56,11 @@ const renderData = (jobAds: JobAd[]) => { ? formatRelative(new Date(ad.autohide_at), new Date()) : "Disabled"} + + confirmDelete(ad)}> + Delete + + ))} diff --git a/src/pages/admin/signups/index.tsx b/src/pages/admin/signups/index.tsx index 84e199a..6c4b762 100644 --- a/src/pages/admin/signups/index.tsx +++ b/src/pages/admin/signups/index.tsx @@ -1,14 +1,36 @@ import React, { useEffect, useState } from "react"; import { NextPage } from "next"; import { formatRelative } from "date-fns"; +import { toast } from "react-toastify"; +import styled from "styled-components"; import AdminListCommon from "@views/admin/AdminListCommon"; -import { Link } from "@components/index"; +import { Button, Link } from "@components/index"; import AddLink from "@components/AddLink"; import { SignupForm } from "@models/Signup"; import SignupApi from "@api/signupApi"; const URL = "/admin/signups"; +const StyledButton = styled(Button) <{ $colorOverride: "red" }>` + background-color: ${(p) => p.$colorOverride}; + border-radius: 8px; + color: white; + font-size: 13px; + font-weight: bold; +`; + +const confirmDelete = async (signup: SignupForm) => { + if (window.confirm(`Delete: ${signup.id}: ${signup.title_fi}/${signup.title_en}; Are you sure?`) === true) { + try { + await SignupApi.deleteForm(signup.id); + toast.success("Signup removed successfully 😎"); + window.location.reload(); // TODO: Fetch/update event list, so user sees the signup in the list + } catch (err) { + toast.error("Uh oh! Something went wrong! Try again later. 😟"); + } + } +}; + const renderData = (signupForms: SignupForm[]) => { if (!signupForms || signupForms.length === 0) { return
No signup forms.
; @@ -33,6 +55,11 @@ const renderData = (signupForms: SignupForm[]) => { {formatRelative(new Date(signupForm.end_time), new Date())} View Send + + confirmDelete(signupForm)}> + Delete + + ))}