diff --git a/package-lock.json b/package-lock.json index 2a11962..aaff90b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,11 +14,11 @@ "@headlessui/react": "^1.7.17", "@next/bundle-analyzer": "^14.1.0", "@nextui-org/react": "^2.2.10", - "@vidstack/react": "^1.11.21", + "@vidstack/react": "^1.12.11", "axios": "^1.6.5", "disqus-react": "^1.1.5", "framer-motion": "^10.18.0", - "hls.js": "^1.5.8", + "hls.js": "^1.5.15", "ioredis": "^5.3.2", "media-icons": "^1.1.4", "mongoose": "^8.1.1", @@ -1996,6 +1996,28 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@floating-ui/core": { + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.6.8.tgz", + "integrity": "sha512-7XJ9cPU+yI2QeLS+FCSlqNFZJq8arvswefkZrYI1yQBbftw6FyrZOxYSh+9S7z7TpeWlRt9zJ5IhM1WIL334jA==", + "dependencies": { + "@floating-ui/utils": "^0.2.8" + } + }, + "node_modules/@floating-ui/dom": { + "version": "1.6.11", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.6.11.tgz", + "integrity": "sha512-qkMCxSR24v2vGkhYDo/UzxfJN3D4syqSjyuTFz6C7XcpU1pASPRieNI0Kj5VP3/503mOfYiGY891ugBX1GlABQ==", + "dependencies": { + "@floating-ui/core": "^1.6.0", + "@floating-ui/utils": "^0.2.8" + } + }, + "node_modules/@floating-ui/utils": { + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.8.tgz", + "integrity": "sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==" + }, "node_modules/@formatjs/ecma402-abstract": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/@formatjs/ecma402-abstract/-/ecma402-abstract-1.18.2.tgz", @@ -5255,11 +5277,12 @@ "dev": true }, "node_modules/@vidstack/react": { - "version": "1.11.21", - "resolved": "https://registry.npmjs.org/@vidstack/react/-/react-1.11.21.tgz", - "integrity": "sha512-eaMh8raSJw8L523UtmooC7IkBxMriny9X1LMk0qsJ1oZ+JGjvgLEYTPkdyLsDIJjrP4hmeeK+12kPZepHSC1pw==", + "version": "1.12.11", + "resolved": "https://registry.npmjs.org/@vidstack/react/-/react-1.12.11.tgz", + "integrity": "sha512-rtSRjjob1k/mkzImN0wWPKYFi/Y7bsuSkDl/RfTxTKlDs4QzFtVwkUfgN1h8y+EUKJvMe9ozVHKdBtGYKDr6FQ==", "dependencies": { - "media-captions": "^1.0.1" + "@floating-ui/dom": "^1.6.10", + "media-captions": "^1.0.4" }, "engines": { "node": ">=18" @@ -7751,9 +7774,9 @@ } }, "node_modules/hls.js": { - "version": "1.5.8", - "resolved": "https://registry.npmjs.org/hls.js/-/hls.js-1.5.8.tgz", - "integrity": "sha512-hJYMPfLhWO7/7+n4f9pn6bOheCGx0WgvVz7k3ouq3Pp1bja48NN+HeCQu3XCGYzqWQF/wo7Sk6dJAyWVJD8ECA==" + "version": "1.5.15", + "resolved": "https://registry.npmjs.org/hls.js/-/hls.js-1.5.15.tgz", + "integrity": "sha512-6cD7xN6bycBHaXz2WyPIaHn/iXFizE5au2yvY5q9aC4wfihxAr16C9fUy4nxh2a3wOw0fEgLRa9dN6wsYjlpNg==" }, "node_modules/html-escaper": { "version": "2.0.2", @@ -8696,9 +8719,9 @@ } }, "node_modules/media-captions": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/media-captions/-/media-captions-1.0.2.tgz", - "integrity": "sha512-QxAFc+XTGZeMx+ZvLtMxEDgAjd0kr1LJ2NekLr1cw/UKENOxK7B9g6HwtuTQzCXxmb4Dknd4T8M7FOqqCK9buA==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/media-captions/-/media-captions-1.0.4.tgz", + "integrity": "sha512-cyDNmuZvvO4H27rcBq2Eudxo9IZRDCOX/I7VEyqbxsEiD2Ei7UYUhG/Sc5fvMZjmathgz3fEK7iAKqvpY+Ux1w==", "engines": { "node": ">=16" } diff --git a/package.json b/package.json index f234d69..e128ae7 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,11 @@ "@headlessui/react": "^1.7.17", "@next/bundle-analyzer": "^14.1.0", "@nextui-org/react": "^2.2.10", - "@vidstack/react": "^1.11.21", + "@vidstack/react": "^1.12.11", "axios": "^1.6.5", "disqus-react": "^1.1.5", "framer-motion": "^10.18.0", - "hls.js": "^1.5.8", + "hls.js": "^1.5.15", "ioredis": "^5.3.2", "media-icons": "^1.1.4", "mongoose": "^8.1.1", diff --git a/src/actions/episode.js b/src/actions/episode.js index b627a21..693c28f 100644 --- a/src/actions/episode.js +++ b/src/actions/episode.js @@ -104,8 +104,13 @@ const fetchAndCacheData = async (id, meta, redis, cacheTime, refresh) => { ); } if (subEpisodes?.length > 0) { + const transformedEpisodes = subEpisodes.map(episode => ({ + ...episode, + id: transformEpisodeId(episode.id) + })); + allepisodes.push({ - episodes: subEpisodes, + episodes: transformedEpisodes, providerId: "zoro", }); } @@ -214,3 +219,14 @@ export const getEpisodes = async (id, status, refresh = false) => { return fetchdata; } }; + + +function transformEpisodeId(episodeId) { + const regex = /^([^$]*)\$episode\$([^$]*)/; + const match = episodeId.match(regex); + + if (match && match[1] && match[2]) { + return `${match[1]}?ep=${match[2]}`; // Construct the desired output with the episode number + } + return episodeId; // Return original ID if no match is found +} \ No newline at end of file diff --git a/src/actions/feedback.js b/src/actions/feedback.js new file mode 100644 index 0000000..0b228dc --- /dev/null +++ b/src/actions/feedback.js @@ -0,0 +1,65 @@ +"use server" +import { connectMongo } from "@/mongodb/db"; +import Feedback from "@/mongodb/models/feedback"; + +export const getFeedbacks = async (req) => { + try { + await connectMongo(); + + const reports = await Feedback.find(); + if (!reports || reports.length === 0) { + return { message: "No feedback reports found" }; + } + + return reports; + } catch (error) { + console.error("Error fetching feedback reports:", error); + return { message: "Failed to retrieve feedback reports. Please try again later." , status: 500}; + } +}; + + +export const createFeedback = async (data) => { + const { title, description, type, severity } = data; + + try { + await connectMongo(); + + const newReport = await Feedback.create({ + title: title, + description: description, + type: type, + severity: severity + }); + + return { message: "Feedback report saved successfully" , status: 201}; + + } catch (error) { + console.error("Error saving feedback report:", error); + return { message: "Failed to save feedback report. Please try again later." , status: 500 }; + } +}; + + +export const deletFeedback = async (id) => { + try { + await connectMongo(); + + if (id) { + const deletedReport = await Feedback.findByIdAndDelete(id); + if (!deletedReport) { + return { message: `Feedback report with ID ${id} not found` }; + } + return { message: `Feedback report with ID ${id} deleted successfully` }; + } else { + // If no ID is provided, delete all feedback reports + const deletedCount = await Feedback.deleteMany({}); + return { message: `Deleted ${deletedCount.deletedCount} feedback reports` }; + } + } catch (error) { + console.error(`Error deleting feedback report${id ? ` with ID ${id}` : 's'}:`, error); + return { message: "Failed to delete feedback report(s). Please try again later." }; + } +}; + + diff --git a/src/actions/source.js b/src/actions/source.js index 88acd40..fddbcd3 100644 --- a/src/actions/source.js +++ b/src/actions/source.js @@ -1,41 +1,53 @@ +"use server" import { ANIME } from "@consumet/extensions"; const gogo = new ANIME.Gogoanime(); export async function getGogoSources(id) { - try { - const data = await gogo.fetchEpisodeSources(id); + try { + const data = await gogo.fetchEpisodeSources(id); - if (!data) return null; + if (!data) return null; - return data; - } catch (error) { - console.log(error); - return null; - } + return data; + } catch (error) { + console.log(error); + return null; + } } -export async function getZoroSources(id) { - try { - const data = await fetch(`${process.env.ZORO_API}/`); - - if (!data) return null; - - return data; - } catch (error) { - console.log(error); - return null; - } +export async function getZoroSources(id, provider, episodeid, epnum, subtype) { + try { + let data; + const API = process.env.ZORO_API; + if (API) { + const res = await fetch(`${API}/anime/episode-srcs?id=${episodeid}&server=vidstreaming&category=${subtype}`); + data = await res.json(); + } else { + console.log(episodeid) + const resp = await fetch(`https://anify.eltik.cc/sources?providerId=${provider}&watchId=${encodeURIComponent(episodeid)}&episodeNumber=${epnum}&id=${id}&subType=${subtype}`); + data = await resp.json(); + } + if (!data) return null; + + return data; + } catch (error) { + console.log(error); + return null; + } } - -export async function getAnimeSources(id, provider, epid, epnum, subdub) { - try { - if (provider === "gogoanime") { - const data = await getGogoSources(epid); - return data; +export async function getAnimeSources(id, provider, epid, epnum, subtype) { + try { + if (provider === "gogoanime") { + const data = await getGogoSources(epid); + return data; + } + if (provider === "zoro") { + const data = await getZoroSources(id, provider, epid, epnum, subtype) + return data; + } + } catch (error) { + console.log(error); + return null; } - } catch (error) { - console.log(error); - return null; - } } diff --git a/src/app/api/admin/feedback-report/route.js b/src/app/api/admin/feedback-report/route.js deleted file mode 100644 index 7d2905f..0000000 --- a/src/app/api/admin/feedback-report/route.js +++ /dev/null @@ -1,70 +0,0 @@ -import { NextResponse } from "next/server"; -import { connectMongo } from "@/mongodb/db"; -import Feedback from "../../../../mongodb/models/feedback"; - -export const GET = async (req) => { - try { - await connectMongo(); - - const reports = await Feedback.find(); - if (!reports || reports.length === 0) { - return NextResponse.json({ message: "No feedback reports found" }); - } - - return NextResponse.json(reports); - } catch (error) { - console.error("Error fetching feedback reports:", error); - return NextResponse.json({ message: "Failed to retrieve feedback reports. Please try again later." }, { status: 500 }); - } -}; - - -export const POST = async (request) => { - const { title, description, type, severity } = await request.json(); - - try { - await connectMongo(); - - const newReport = await Feedback.create({ - title: title, - description: description, - type: type, - severity: severity - }); - - return NextResponse.json( - { message: "Feedback report saved successfully" }, - { status: 201 } - ); - - } catch (error) { - console.error("Error saving feedback report:", error); - return NextResponse.json({ message: "Failed to save feedback report. Please try again later." }, { status: 500 }); - } -}; - - -export const DELETE = async (req) => { - const { id } = await req.json(); - - try { - await connectMongo(); - - if (id) { - const deletedReport = await Feedback.findByIdAndDelete(id); - if (!deletedReport) { - return NextResponse.json({ message: `Feedback report with ID ${id} not found` }, { status: 404 }); - } - return NextResponse.json({ message: `Feedback report with ID ${id} deleted successfully` }); - } else { - // If no ID is provided, delete all feedback reports - const deletedCount = await Feedback.deleteMany({}); - return NextResponse.json({ message: `Deleted ${deletedCount.deletedCount} feedback reports` }); - } - } catch (error) { - console.error(`Error deleting feedback report${id ? ` with ID ${id}` : 's'}:`, error); - return NextResponse.json({ message: "Failed to delete feedback report(s). Please try again later." }, { status: 500 }); - } -}; - - diff --git a/src/app/api/episode/[...animeid]/route.js b/src/app/api/episode/[...animeid]/route.js deleted file mode 100644 index ceb04e4..0000000 --- a/src/app/api/episode/[...animeid]/route.js +++ /dev/null @@ -1,210 +0,0 @@ -async function fetchGogoanime(sub, dub) { - try { - async function fetchData(id) { - const { data } = await axios.get( - `${process.env.CONSUMET_URI}/anime/gogoanime/info/${id}` - ); - if (data?.message === "Anime not found" && data?.episodes?.length < 1) { - return []; - } - return data?.episodes; - } - - const [subData, dubData] = await Promise.all([ - sub !== "" ? fetchData(sub) : Promise.resolve([]), - dub !== "" ? fetchData(dub) : Promise.resolve([]), - ]); - - const array = [ - { - consumet: true, - providerId: "gogoanime", - episodes: { - ...(subData && subData.length > 0 && { sub: subData }), - ...(dubData && dubData.length > 0 && { dub: dubData }), - }, - }, - ]; - - return array; - } catch (error) { - console.error("Error fetching consumet gogoanime:", error.message); - return []; - } -} - -async function fetchZoro(id) { - try { - const { data } = await axios.get(`${process.env.ZORO_URI}/anime/episodes/${id}`); - if (!data?.episodes) return []; - - const array = [ - { - providerId: "zoro", - episodes: data?.episodes, - }, - ]; - - return array; - } catch (error) { - console.error("Error fetching zoro:", error.message); - return []; - } -} - -async function fetchEpisodeMeta(id, available = false) { - try { - if (available) { - return null; - } - // const { data } = await axios.get( - // `https://api.anify.tv/content-metadata/${id}` - // ); - // if (!data) return []; - - // const metadata = data?.find((i) => i.providerId === "tvdb") || data[0]; - // return metadata?.data; - const data = await axios.get(`https://api.ani.zip/mappings?anilist_id=${id}`); - const episodesArray = Object.values(data?.data?.episodes); - - if(!episodesArray){ - return []; - } - return episodesArray - - } catch (error) { - console.error("Error fetching and processing meta:", error.message); - return []; - } -} - -const fetchAndCacheData = async (id, meta, redis, cacheTime, refresh) => { - let malsync; - if(id){ - malsync = await MalSync(id); - } - const promises = []; - - if (malsync) { - console.log(malsync) - const gogop = malsync.gogoanime; - const zorop = malsync.zoro - - if (gogop) { - promises.push(fetchGogoanime(gogop.sub, gogop.dub)); - } else { - promises.push(Promise.resolve([])); - } - - if (zorop) { - promises.push(fetchZoro(zorop.sub)); - } else { - promises.push(Promise.resolve([])); - } - promises.push(fetchEpisodeMeta(id, !refresh)); - - } else { - promises.push(fetchConsumet(id)); - promises.push(fetchAnify(id)); - promises.push(fetchEpisodeMeta(id, !refresh)); - } - const [consumet, anify, cover] = await Promise.all(promises); - - // Check if redis is available - if (redis) { - if (consumet.length > 0 || anify.length > 0) { - await redis.setex(`episode:${id}`, cacheTime, JSON.stringify([...consumet, ...anify])); - } - - const combinedData = [...consumet, ...anify]; - let data = combinedData; - if (refresh) { - if (cover && cover?.length > 0) { - try { - await redis.setex(`meta:${id}`, cacheTime, JSON.stringify(cover)); - data = await CombineEpisodeMeta(combinedData, cover); - } catch (error) { - console.error("Error serializing cover:", error.message); - } - } - else if (meta) { - data = await CombineEpisodeMeta(combinedData, JSON.parse(meta)); - } - } else if (meta) { - data = await CombineEpisodeMeta(combinedData, JSON.parse(meta)); - } - - return data; - } else { - console.error("Redis URL not provided. Caching not possible."); - return [...consumet, ...anify]; - } -}; - -export const GET = async (req, { params }) => { - const url = new URL(req.url); - const id = params.animeid[0]; - const releasing = url.searchParams.get('releasing') || false; - const refresh = url.searchParams.get('refresh') === 'true' || false; - - let cacheTime = null; - if (releasing === "true") { - cacheTime = 60 * 60 * 3; - } else if (releasing === "false") { - cacheTime = 60 * 60 * 24 * 45; - } - - let meta = null; - let cached; - - if (redis) { - try { - // // Find keys matching the pattern "meta:*" - // const keys = await redis.keys("meta:*"); - - // // Delete keys matching the pattern "meta:*" - // if (keys.length > 0) { - // await redis.del(keys); - // console.log(`Deleted ${keys.length} keys matching the pattern "meta:*"`); - // } - meta = await redis.get(`meta:${id}`); - if (JSON.parse(meta)?.length === 0) { - await redis.del(`meta:${id}`); - console.log("deleted meta cache"); - meta = null; - } - cached = await redis.get(`episode:${id}`); - if (JSON.parse(cached)?.length === 0) { - await redis.del(`episode:${id}`); - cached = null; - } - let data; - if (refresh) { - data = await fetchAndCacheData(id, meta, redis, cacheTime, refresh); - } - if (data?.length > 0) { - console.log("deleted cache"); - return NextResponse.json(data); - } - - console.log("using redis"); - } catch (error) { - console.error("Error checking Redis cache:", error.message); - } - } - - if (cached) { - try { - let cachedData = JSON.parse(cached); - if (meta) { - cachedData = await CombineEpisodeMeta(cachedData, JSON.parse(meta)); - } - return NextResponse.json(cachedData); - } catch (error) { - console.error("Error parsing cached data:", error.message); - } - } else { - const fetchdata = await fetchAndCacheData(id, meta, redis, cacheTime, !refresh); - return NextResponse.json(fetchdata); - } -}; \ No newline at end of file diff --git a/src/app/api/recent/route.js b/src/app/api/recent/route.js deleted file mode 100644 index b5afa06..0000000 --- a/src/app/api/recent/route.js +++ /dev/null @@ -1,66 +0,0 @@ -import axios from "axios"; -import { redis } from "@/lib/rediscache"; -import { NextResponse } from "next/server"; - -axios.interceptors.request.use(config => { - config.timeout = 9000; - return config; -}) - -async function fetchRecent() { - try { - const { data } = await axios.get( - `https://anify.eltik.cc/recent?type=anime&page=1&perPage=20&fields=[id,title,status,format,currentEpisode,coverImage,episodes,totalEpisodes]` - ); - - const mappedData = data.map((i) => { - const episodesData = i?.episodes?.data; - const getEpisodes = episodesData ? episodesData.find((x) => x.providerId === "gogoanime") || episodesData[0] : []; - const getEpisode = getEpisodes?.episodes?.find( - (x) => x.number === i.currentEpisode - ); - - return { - id: i.id, - latestEpisode: getEpisode?.id ? getEpisode.id.substring(1) : '', - title: i.title, - status: i.status, - format: i.format, - totalEpisodes: i?.totalEpisodes, - currentEpisode: i.currentEpisode, - coverImage: i.coverImage, - }; - }); - return mappedData; - } catch (error) { - console.error("Error fetching Recent Episodes:", error); - return []; - } -} - -export const GET = async (req) => { - let cached; - if (redis) { - console.log('using redis') - cached = await redis.get('recent'); - } - if (cached) { - return NextResponse.json(JSON.parse(cached)); - } - else { - const data = await fetchRecent(); - if (data && data?.length > 0) { - if (redis) { - await redis.set( - "recent", - JSON.stringify(data), - "EX", - 60 * 60 - ); - } - return NextResponse.json(data); - } else { - return NextResponse.json({ message: "Recent Episodes not found" }); - } - } -}; \ No newline at end of file diff --git a/src/app/api/schedule/route.js b/src/app/api/schedule/route.js deleted file mode 100644 index 586cd03..0000000 --- a/src/app/api/schedule/route.js +++ /dev/null @@ -1,61 +0,0 @@ -import axios from "axios"; -import { redis } from "@/lib/rediscache"; -import { NextResponse } from "next/server"; - -async function fetchSchedule() { - try { - const { data } = await axios.get( - `https://anify.eltik.cc/schedule?fields=[id,title,coverImage]` - ); - return data; - } catch (error) { - console.error("Error fetching schedule:", error); - return null; - } -} - -async function refreshCache() { - const today = new Date().getDay(); - if (today === 1) { - const newData = await fetchSchedule(); - if (newData) { - if (redis) { - await redis.set( - "schedule", - JSON.stringify(newData), - "EX", - 60 * 60 * 24 * 7 - ); - } - console.log("Cache refreshed successfully."); - } - } -} - -const refreshInterval = 24 * 60 * 60 * 1000; -const cacheRefreshInterval = setInterval(refreshCache, refreshInterval); - -export const GET = async (req) => { - let cached; - if (redis) { - cached = await redis.get("schedule"); - } - if (cached) { - return NextResponse.json(JSON.parse(cached)); - } else { - const data = await fetchSchedule(); - if (data) { - if (redis) { - await redis.set( - "schedule", - JSON.stringify(data), - "EX", - 60 * 60 * 24 * 7 - ); - } - return NextResponse.json(data); - } else { - return NextResponse.json({ message: "Schedule not found" }); - } - } -}; diff --git a/src/app/api/source/[...epsource]/route.js b/src/app/api/source/[...epsource]/route.js deleted file mode 100644 index cfcb4ae..0000000 --- a/src/app/api/source/[...epsource]/route.js +++ /dev/null @@ -1,74 +0,0 @@ -import axios from 'axios' -import { redis } from '@/lib/rediscache'; -import { NextResponse, NextRequest } from "next/server" - -async function consumetEpisode(id) { - try { - const { data } = await axios.get( - `${process.env.CONSUMET_URI}/meta/anilist/watch/${id}` - ); - return data; - } catch (error) { - console.error(error); - return null; - } - } - -async function zoroEpisode(provider, episodeid, epnum, id, subtype) { - try { - const cleanEpisodeId = episodeid.replace("/watch/", ""); - const { data } = await axios.get(`${process.env.ZORO_URI}/anime/episode-srcs?id=${cleanEpisodeId}&server=vidstreaming&category=${subtype}`); - return data; - } catch (error) { - console.error(error); - return AnifyEpisode(provider, episodeid, epnum, id, subtype); - } - } - - async function AnifyEpisode(provider, episodeid, epnum, id, subtype) { - try { - const { data } = await axios.get( - `https://api.anify.tv/sources?providerId=${provider}&watchId=${encodeURIComponent( - episodeid - )}&episodeNumber=${epnum}&id=${id}&subType=${subtype}` - ); - return data; - } catch (error) { - console.error(error); - return null; - } - } - -export const POST = async (req,{params}) => { - const id = params.epsource[0]; - const {source, provider, episodeid, episodenum, subtype} = await req.json(); - // let cacheTime = 25 * 60; - // let cached = await redis.get(`source:${params.epid[0]}`); - - // if (cached) { - // const cachedData = JSON.parse(cached); - // return NextResponse.json(cachedData); - // } else { - // const data = await consumetEpisode(params.epid[0]); - - // await redis.setex(`source:${params.epid[0]}`, cacheTime, JSON.stringify(data)); - - // return NextResponse.json(data); - // } - - // console.log(provider,episodeid,episodenum,id,subtype) - if (source === "consumet") { - const data = await consumetEpisode(episodeid); - return NextResponse.json(data); - } - - if (source === "anify" && provider === "zoro") { - const data = await zoroEpisode(provider, episodeid, episodenum, id, subtype); - return NextResponse.json(data); - } - - if(source === "anify"){ - const data = await AnifyEpisode(provider, episodeid, episodenum, id, subtype); - return NextResponse.json(data); - } -} \ No newline at end of file diff --git a/src/components/home/Herosection.js b/src/components/home/Herosection.js index d95ee63..3975c36 100644 --- a/src/components/home/Herosection.js +++ b/src/components/home/Herosection.js @@ -95,7 +95,7 @@ function Herosection({ data }) { {Month[populardata?.startDate?.month]} {populardata?.startDate?.day}, {populardata?.startDate?.year} - + {populardata?.nextAiringEpisode?.episode - 1 || populardata?.episodes}
{populardata?.description.replace(/<.*?>/g, '')}
diff --git a/src/components/navbar/Feedbackform.js b/src/components/navbar/Feedbackform.js index cc6dd0e..72eaeca 100644 --- a/src/components/navbar/Feedbackform.js +++ b/src/components/navbar/Feedbackform.js @@ -1,6 +1,7 @@ import React, { useState } from "react"; import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Button, Input, Select, SelectItem, Textarea } from "@nextui-org/react"; import { toast } from 'sonner'; +import { createFeedback } from '@/actions/feedback'; export default function Feedbackform({ isOpen, onOpenChange }) { const [title, setTitle] = useState(""); @@ -12,7 +13,7 @@ export default function Feedbackform({ isOpen, onOpenChange }) { { label: "Suggestion", value: "Suggestion" }, { label: "Bug Report", value: "Bug Report" }, { label: "Feature Request", value: "Feature Request" }, - { label: "Other", value: "Other"} + { label: "Other", value: "Other" } ]; const severityOptions = [ @@ -27,20 +28,14 @@ export default function Feedbackform({ isOpen, onOpenChange }) { toast.error('Title and Description are required!'); return; } - + try { - const response = await fetch(`/api/admin/feedback-report`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - title, - description, - type: feedbackType, - severity: severityLevel - }), - }); + const response = await createFeedback({ + title, + description, + type: feedbackType || "Bug Report", + severity: severityLevel || "Low" + }) if (response.status === 201) { toast.success('Feedback report successfully submitted'); setTitle(""); @@ -55,7 +50,7 @@ export default function Feedbackform({ isOpen, onOpenChange }) { toast.error('An error occurred while submitting the feedback report. Please try again later.'); } }; - + return ( <>