Accepted incoming changes
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import getTags from "@/lib/api/controllers/tags/getTags";
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { LinkRequestQuery } from "@/types/global";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default async function collections(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
if (req.method === "GET") {
|
||||
// Convert the type of the request query to "LinkRequestQuery"
|
||||
const convertedData: Omit<LinkRequestQuery, "tagId"> = {
|
||||
sort: Number(req.query.sort as string),
|
||||
collectionId: req.query.collectionId
|
||||
? Number(req.query.collectionId as string)
|
||||
: undefined,
|
||||
};
|
||||
|
||||
if (!convertedData.collectionId) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ response: "Please choose a valid collection." });
|
||||
}
|
||||
|
||||
const collection = await prisma.collection.findFirst({
|
||||
where: {
|
||||
id: convertedData.collectionId,
|
||||
isPublic: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!collection) {
|
||||
return res.status(404).json({ response: "Collection not found." });
|
||||
}
|
||||
|
||||
const tags = await getTags({
|
||||
collectionId: collection.id,
|
||||
});
|
||||
|
||||
return res.status(tags?.status || 500).json({ response: tags?.response });
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@ export default async function tags(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!user) return;
|
||||
|
||||
if (req.method === "GET") {
|
||||
const tags = await getTags(user.id);
|
||||
return res.status(tags.status).json({ response: tags.response });
|
||||
const tags = await getTags({
|
||||
userId: user.id,
|
||||
});
|
||||
return res.status(tags?.status || 500).json({ response: tags?.response });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,21 @@ export default function Index() {
|
||||
<i className="bi-three-dots text-xl" title="More"></i>
|
||||
</div>
|
||||
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-box mt-1">
|
||||
<li>
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => {
|
||||
(document?.activeElement as HTMLElement)?.blur();
|
||||
for (const link of links) {
|
||||
if (link.url) window.open(link.url, "_blank");
|
||||
}
|
||||
}}
|
||||
className="whitespace-nowrap"
|
||||
>
|
||||
{t("open_all_links")}
|
||||
</div>
|
||||
</li>
|
||||
{permissions === true && (
|
||||
<li>
|
||||
<div
|
||||
|
||||
+161
-76
@@ -1,7 +1,6 @@
|
||||
import MainLayout from "@/layouts/MainLayout";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import useWindowDimensions from "@/hooks/useWindowDimensions";
|
||||
import React from "react";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { MigrationFormat, MigrationRequest, ViewMode } from "@/types/global";
|
||||
@@ -16,16 +15,23 @@ import { useCollections } from "@/hooks/store/collections";
|
||||
import { useTags } from "@/hooks/store/tags";
|
||||
import { useDashboardData } from "@/hooks/store/dashboardData";
|
||||
import Links from "@/components/LinkViews/Links";
|
||||
import useLocalSettingsStore from "@/store/localSettings";
|
||||
import { useUpdateUser, useUser } from "@/hooks/store/user";
|
||||
import SurveyModal from "@/components/ModalContent/SurveyModal";
|
||||
|
||||
export default function Dashboard() {
|
||||
const { t } = useTranslation();
|
||||
const { data: collections = [] } = useCollections();
|
||||
const dashboardData = useDashboardData();
|
||||
const {
|
||||
data: { links = [], numberOfPinnedLinks } = { links: [] },
|
||||
...dashboardData
|
||||
} = useDashboardData();
|
||||
const { data: tags = [] } = useTags();
|
||||
const { data: account = [] } = useUser();
|
||||
|
||||
const [numberOfLinks, setNumberOfLinks] = useState(0);
|
||||
|
||||
const [showLinks, setShowLinks] = useState(3);
|
||||
const { settings } = useLocalSettingsStore();
|
||||
|
||||
useEffect(() => {
|
||||
setNumberOfLinks(
|
||||
@@ -37,29 +43,44 @@ export default function Dashboard() {
|
||||
);
|
||||
}, [collections]);
|
||||
|
||||
const handleNumberOfLinksToShow = () => {
|
||||
if (window.innerWidth > 1900) {
|
||||
setShowLinks(10);
|
||||
} else if (window.innerWidth > 1500) {
|
||||
setShowLinks(8);
|
||||
} else if (window.innerWidth > 880) {
|
||||
setShowLinks(6);
|
||||
} else if (window.innerWidth > 550) {
|
||||
setShowLinks(4);
|
||||
} else setShowLinks(2);
|
||||
};
|
||||
|
||||
const { width } = useWindowDimensions();
|
||||
|
||||
useEffect(() => {
|
||||
handleNumberOfLinksToShow();
|
||||
}, [width]);
|
||||
if (
|
||||
process.env.NEXT_PUBLIC_STRIPE === "true" &&
|
||||
account &&
|
||||
account.id &&
|
||||
account.referredBy === null &&
|
||||
// if user is using Linkwarden for more than 3 days
|
||||
new Date().getTime() - new Date(account.createdAt).getTime() >
|
||||
3 * 24 * 60 * 60 * 1000
|
||||
) {
|
||||
setTimeout(() => {
|
||||
setShowsSurveyModal(true);
|
||||
}, 1000);
|
||||
}
|
||||
}, [account]);
|
||||
|
||||
const importBookmarks = async (e: any, format: MigrationFormat) => {
|
||||
const file: File = e.target.files[0];
|
||||
const numberOfLinksToShow = useMemo(() => {
|
||||
if (window.innerWidth > 1900) {
|
||||
return 10;
|
||||
} else if (window.innerWidth > 1500) {
|
||||
return 8;
|
||||
} else if (window.innerWidth > 880) {
|
||||
return 6;
|
||||
} else if (window.innerWidth > 550) {
|
||||
return 4;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const importBookmarks = async (
|
||||
e: React.ChangeEvent<HTMLInputElement>,
|
||||
format: MigrationFormat
|
||||
) => {
|
||||
const file: File | null = e.target.files && e.target.files[0];
|
||||
|
||||
if (file) {
|
||||
var reader = new FileReader();
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file, "UTF-8");
|
||||
reader.onload = async function (e) {
|
||||
const load = toast.loading("Importing...");
|
||||
@@ -71,23 +92,44 @@ export default function Dashboard() {
|
||||
data: request,
|
||||
};
|
||||
|
||||
const response = await fetch("/api/v1/migration", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
try {
|
||||
const response = await fetch("/api/v1/migration", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
await response.json();
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
toast.dismiss(load);
|
||||
|
||||
toast.dismiss(load);
|
||||
toast.error(
|
||||
errorData.response ||
|
||||
"Failed to import bookmarks. Please try again."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
toast.success("Imported the Bookmarks! Reloading the page...");
|
||||
await response.json();
|
||||
toast.dismiss(load);
|
||||
toast.success("Imported the Bookmarks! Reloading the page...");
|
||||
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 2000);
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 2000);
|
||||
} catch (error) {
|
||||
console.error("Request failed", error);
|
||||
toast.dismiss(load);
|
||||
toast.error(
|
||||
"An error occurred while importing bookmarks. Please check the logs for more info."
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = function (e) {
|
||||
console.log("Error:", e);
|
||||
console.log("Error reading file:", e);
|
||||
toast.error(
|
||||
"Failed to read the file. Please make sure the file is correct and try again."
|
||||
);
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -98,6 +140,42 @@ export default function Dashboard() {
|
||||
(localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card
|
||||
);
|
||||
|
||||
const [showSurveyModal, setShowsSurveyModal] = useState(false);
|
||||
|
||||
const { data: user } = useUser();
|
||||
const updateUser = useUpdateUser();
|
||||
|
||||
const [submitLoader, setSubmitLoader] = useState(false);
|
||||
|
||||
const submitSurvey = async (referer: string, other?: string) => {
|
||||
if (submitLoader) return;
|
||||
|
||||
setSubmitLoader(true);
|
||||
|
||||
const load = toast.loading(t("applying"));
|
||||
|
||||
await updateUser.mutateAsync(
|
||||
{
|
||||
...user,
|
||||
referredBy: referer === "other" ? "Other: " + other : referer,
|
||||
},
|
||||
{
|
||||
onSettled: (data, error) => {
|
||||
console.log(data, error);
|
||||
setSubmitLoader(false);
|
||||
toast.dismiss(load);
|
||||
|
||||
if (error) {
|
||||
toast.error(error.message);
|
||||
} else {
|
||||
toast.success(t("thanks_for_feedback"));
|
||||
setShowsSurveyModal(false);
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<MainLayout>
|
||||
<div style={{ flex: "1 1 auto" }} className="p-5 flex flex-col gap-5">
|
||||
@@ -110,32 +188,30 @@ export default function Dashboard() {
|
||||
<ViewDropdown viewMode={viewMode} setViewMode={setViewMode} />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="flex justify-evenly flex-col xl:flex-row xl:items-center gap-2 xl:w-full h-full rounded-2xl p-8 border border-neutral-content bg-base-200">
|
||||
<DashboardItem
|
||||
name={numberOfLinks === 1 ? t("link") : t("links")}
|
||||
value={numberOfLinks}
|
||||
icon={"bi-link-45deg"}
|
||||
/>
|
||||
<div className="xl:flex flex flex-col sm:grid grid-cols-2 gap-3 xl:flex-row xl:justify-evenly xl:w-full h-full">
|
||||
<DashboardItem
|
||||
name={numberOfLinks === 1 ? t("link") : t("links")}
|
||||
value={numberOfLinks}
|
||||
icon={"bi-link-45deg"}
|
||||
/>
|
||||
|
||||
<div className="divider xl:divider-horizontal"></div>
|
||||
<DashboardItem
|
||||
name={collections.length === 1 ? t("collection") : t("collections")}
|
||||
value={collections.length}
|
||||
icon={"bi-folder"}
|
||||
/>
|
||||
|
||||
<DashboardItem
|
||||
name={
|
||||
collections.length === 1 ? t("collection") : t("collections")
|
||||
}
|
||||
value={collections.length}
|
||||
icon={"bi-folder"}
|
||||
/>
|
||||
<DashboardItem
|
||||
name={tags.length === 1 ? t("tag") : t("tags")}
|
||||
value={tags.length}
|
||||
icon={"bi-hash"}
|
||||
/>
|
||||
|
||||
<div className="divider xl:divider-horizontal"></div>
|
||||
|
||||
<DashboardItem
|
||||
name={tags.length === 1 ? t("tag") : t("tags")}
|
||||
value={tags.length}
|
||||
icon={"bi-hash"}
|
||||
/>
|
||||
</div>
|
||||
<DashboardItem
|
||||
name={t("pinned")}
|
||||
value={numberOfPinnedLinks}
|
||||
icon={"bi-pin-angle"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between items-center">
|
||||
@@ -157,10 +233,7 @@ export default function Dashboard() {
|
||||
|
||||
<div
|
||||
style={{
|
||||
flex:
|
||||
dashboardData.data || dashboardData.isLoading
|
||||
? "0 1 auto"
|
||||
: "1 1 auto",
|
||||
flex: links || dashboardData.isLoading ? "0 1 auto" : "1 1 auto",
|
||||
}}
|
||||
className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
|
||||
>
|
||||
@@ -168,21 +241,22 @@ export default function Dashboard() {
|
||||
<div className="w-full">
|
||||
<Links
|
||||
layout={viewMode}
|
||||
placeholderCount={showLinks / 2}
|
||||
placeholderCount={settings.columns || 1}
|
||||
useData={dashboardData}
|
||||
/>
|
||||
</div>
|
||||
) : dashboardData.data &&
|
||||
dashboardData.data[0] &&
|
||||
!dashboardData.isLoading ? (
|
||||
) : links && links[0] && !dashboardData.isLoading ? (
|
||||
<div className="w-full">
|
||||
<Links
|
||||
links={dashboardData.data.slice(0, showLinks)}
|
||||
links={links.slice(
|
||||
0,
|
||||
settings.columns ? settings.columns * 2 : numberOfLinksToShow
|
||||
)}
|
||||
layout={viewMode}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="sky-shadow flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200">
|
||||
<div className="flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">
|
||||
<p className="text-center text-2xl">
|
||||
{t("view_added_links_here")}
|
||||
</p>
|
||||
@@ -310,23 +384,28 @@ export default function Dashboard() {
|
||||
<div className="w-full">
|
||||
<Links
|
||||
layout={viewMode}
|
||||
placeholderCount={showLinks / 2}
|
||||
placeholderCount={settings.columns || 1}
|
||||
useData={dashboardData}
|
||||
/>
|
||||
</div>
|
||||
) : dashboardData.data?.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
|
||||
) : links?.some((e: any) => e.pinnedBy && e.pinnedBy[0]) ? (
|
||||
<div className="w-full">
|
||||
<Links
|
||||
links={dashboardData.data
|
||||
.filter((e) => e.pinnedBy && e.pinnedBy[0])
|
||||
.slice(0, showLinks)}
|
||||
links={links
|
||||
.filter((e: any) => e.pinnedBy && e.pinnedBy[0])
|
||||
.slice(
|
||||
0,
|
||||
settings.columns
|
||||
? settings.columns * 2
|
||||
: numberOfLinksToShow
|
||||
)}
|
||||
layout={viewMode}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
style={{ flex: "1 1 auto" }}
|
||||
className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200"
|
||||
className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200"
|
||||
>
|
||||
<i className="bi-pin mx-auto text-6xl text-primary"></i>
|
||||
<p className="text-center text-2xl">
|
||||
@@ -339,9 +418,15 @@ export default function Dashboard() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{newLinkModal ? (
|
||||
<NewLinkModal onClose={() => setNewLinkModal(false)} />
|
||||
) : undefined}
|
||||
{showSurveyModal && (
|
||||
<SurveyModal
|
||||
submit={submitSurvey}
|
||||
onClose={() => {
|
||||
setShowsSurveyModal(false);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{newLinkModal && <NewLinkModal onClose={() => setNewLinkModal(false)} />}
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
|
||||
+37
-37
@@ -1,70 +1,70 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import {
|
||||
ArchivedFormat,
|
||||
LinkIncludingShortenedCollectionAndTags,
|
||||
} from "@/types/global";
|
||||
import { ArchivedFormat } from "@/types/global";
|
||||
import ReadableView from "@/components/ReadableView";
|
||||
import getServerSideProps from "@/lib/client/getServerSideProps";
|
||||
import { useGetLink, useLinks } from "@/hooks/store/links";
|
||||
import { useGetLink } from "@/hooks/store/links";
|
||||
import clsx from "clsx";
|
||||
|
||||
export default function Index() {
|
||||
const { links } = useLinks();
|
||||
|
||||
const getLink = useGetLink();
|
||||
|
||||
const [link, setLink] = useState<LinkIncludingShortenedCollectionAndTags>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchLink = async () => {
|
||||
if (router.query.id) {
|
||||
await getLink.mutateAsync(Number(router.query.id));
|
||||
}
|
||||
};
|
||||
|
||||
fetchLink();
|
||||
if (router.query.id) {
|
||||
getLink.mutateAsync({ id: Number(router.query.id) });
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (links && links[0])
|
||||
setLink(links.find((e) => e.id === Number(router.query.id)));
|
||||
}, [links]);
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<div className={clsx(getLink.isPending ? "flex h-screen" : "relative")}>
|
||||
{/* <div className="fixed left-1/2 transform -translate-x-1/2 w-fit py-1 px-3 bg-base-200 border border-neutral-content rounded-md">
|
||||
Readable
|
||||
</div> */}
|
||||
{link && Number(router.query.format) === ArchivedFormat.readability && (
|
||||
<ReadableView link={link} />
|
||||
)}
|
||||
{link && Number(router.query.format) === ArchivedFormat.monolith && (
|
||||
{getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.readability ? (
|
||||
<ReadableView link={getLink.data} />
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.monolith ? (
|
||||
<iframe
|
||||
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.monolith}`}
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.monolith}`}
|
||||
className="w-full h-screen border-none"
|
||||
></iframe>
|
||||
)}
|
||||
{link && Number(router.query.format) === ArchivedFormat.pdf && (
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.pdf ? (
|
||||
<iframe
|
||||
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.pdf}`}
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.pdf}`}
|
||||
className="w-full h-screen border-none"
|
||||
></iframe>
|
||||
)}
|
||||
{link && Number(router.query.format) === ArchivedFormat.png && (
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.png ? (
|
||||
<img
|
||||
alt=""
|
||||
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.png}`}
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.png}`}
|
||||
className="w-fit mx-auto"
|
||||
/>
|
||||
)}
|
||||
{link && Number(router.query.format) === ArchivedFormat.jpeg && (
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.jpeg ? (
|
||||
<img
|
||||
alt=""
|
||||
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}`}
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.jpeg}`}
|
||||
className="w-fit mx-auto"
|
||||
/>
|
||||
) : getLink.error ? (
|
||||
<p>404 - Not found</p>
|
||||
) : (
|
||||
<div className="max-w-3xl p-5 m-auto w-full flex flex-col items-center gap-5">
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
+212
-146
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
import getPublicCollectionData from "@/lib/client/getPublicCollectionData";
|
||||
import {
|
||||
AccountSettings,
|
||||
CollectionIncludingMembersAndLinkCount,
|
||||
Sort,
|
||||
ViewMode,
|
||||
@@ -21,6 +22,7 @@ import getServerSideProps from "@/lib/client/getServerSideProps";
|
||||
import LinkListOptions from "@/components/LinkListOptions";
|
||||
import { usePublicLinks } from "@/hooks/store/publicLinks";
|
||||
import Links from "@/components/LinkViews/Links";
|
||||
import { usePublicTags } from "@/hooks/store/publicTags";
|
||||
|
||||
export default function PublicCollections() {
|
||||
const { t } = useTranslation();
|
||||
@@ -29,15 +31,35 @@ export default function PublicCollections() {
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const [collectionOwner, setCollectionOwner] = useState({
|
||||
id: null as unknown as number,
|
||||
name: "",
|
||||
username: "",
|
||||
image: "",
|
||||
archiveAsScreenshot: undefined as unknown as boolean,
|
||||
archiveAsMonolith: undefined as unknown as boolean,
|
||||
archiveAsPDF: undefined as unknown as boolean,
|
||||
});
|
||||
const [collectionOwner, setCollectionOwner] = useState<
|
||||
Partial<AccountSettings>
|
||||
>({});
|
||||
|
||||
const handleTagSelection = (tag: string | undefined) => {
|
||||
if (tag) {
|
||||
Object.keys(searchFilter).forEach(
|
||||
(v) =>
|
||||
(searchFilter[
|
||||
v as keyof {
|
||||
name: boolean;
|
||||
url: boolean;
|
||||
description: boolean;
|
||||
tags: boolean;
|
||||
textContent: boolean;
|
||||
}
|
||||
] = false)
|
||||
);
|
||||
searchFilter.tags = true;
|
||||
return router.push(
|
||||
"/public/collections/" +
|
||||
router.query.id +
|
||||
"?q=" +
|
||||
encodeURIComponent(tag || "")
|
||||
);
|
||||
} else {
|
||||
return router.push("/public/collections/" + router.query.id);
|
||||
}
|
||||
};
|
||||
|
||||
const [searchFilter, setSearchFilter] = useState({
|
||||
name: true,
|
||||
@@ -51,6 +73,8 @@ export default function PublicCollections() {
|
||||
Number(localStorage.getItem("sortBy")) ?? Sort.DateNewestFirst
|
||||
);
|
||||
|
||||
const { data: tags } = usePublicTags();
|
||||
|
||||
const { links, data } = usePublicLinks({
|
||||
sort: sortBy,
|
||||
searchQueryString: router.query.q
|
||||
@@ -62,10 +86,8 @@ export default function PublicCollections() {
|
||||
searchByTextContent: searchFilter.textContent,
|
||||
searchByTags: searchFilter.tags,
|
||||
});
|
||||
|
||||
const [collection, setCollection] =
|
||||
useState<CollectionIncludingMembersAndLinkCount>();
|
||||
|
||||
useEffect(() => {
|
||||
if (router.query.id) {
|
||||
getPublicCollectionData(Number(router.query.id)).then((res) => {
|
||||
@@ -93,160 +115,204 @@ export default function PublicCollections() {
|
||||
(localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card
|
||||
);
|
||||
|
||||
return collection ? (
|
||||
<div
|
||||
className="h-96"
|
||||
style={{
|
||||
backgroundImage: `linear-gradient(${collection?.color}30 10%, ${
|
||||
settings.theme === "dark" ? "#262626" : "#f3f4f6"
|
||||
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
|
||||
}}
|
||||
>
|
||||
{collection ? (
|
||||
<Head>
|
||||
<title>{collection.name} | Linkwarden</title>
|
||||
<meta
|
||||
property="og:title"
|
||||
content={`${collection.name} | Linkwarden`}
|
||||
key="title"
|
||||
/>
|
||||
</Head>
|
||||
) : undefined}
|
||||
<div className="lg:w-3/4 w-full mx-auto p-5 bg">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-4xl font-thin mb-2 capitalize mt-10">
|
||||
{collection.name}
|
||||
</p>
|
||||
<div className="flex gap-2 items-center mt-8 min-w-fit">
|
||||
<ToggleDarkMode />
|
||||
if (!collection) return <></>;
|
||||
else
|
||||
return (
|
||||
<div
|
||||
className="h-96"
|
||||
style={{
|
||||
backgroundImage: `linear-gradient(${collection?.color}30 10%, ${
|
||||
settings.theme === "dark" ? "#262626" : "#f3f4f6"
|
||||
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
|
||||
}}
|
||||
>
|
||||
{collection && (
|
||||
<Head>
|
||||
<title>{collection.name} | Linkwarden</title>
|
||||
<meta
|
||||
property="og:title"
|
||||
content={`${collection.name} | Linkwarden`}
|
||||
key="title"
|
||||
/>
|
||||
</Head>
|
||||
)}
|
||||
<div className="lg:w-3/4 w-full mx-auto p-5 bg">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-4xl font-thin mb-2 capitalize mt-10">
|
||||
{collection.name}
|
||||
</p>
|
||||
<div className="flex gap-2 items-center mt-8 min-w-fit">
|
||||
<ToggleDarkMode />
|
||||
|
||||
<Link href="https://linkwarden.app/" target="_blank">
|
||||
<Image
|
||||
src={`/icon.png`}
|
||||
width={551}
|
||||
height={551}
|
||||
alt="Linkwarden"
|
||||
title={t("list_created_with_linkwarden")}
|
||||
className="h-8 w-fit mx-auto rounded"
|
||||
/>
|
||||
</Link>
|
||||
<Link href="https://linkwarden.app/" target="_blank">
|
||||
<Image
|
||||
src={`/icon.png`}
|
||||
width={551}
|
||||
height={551}
|
||||
alt="Linkwarden"
|
||||
title={t("list_created_with_linkwarden")}
|
||||
className="h-8 w-fit mx-auto rounded"
|
||||
/>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-3">
|
||||
<div className={`min-w-[15rem]`}>
|
||||
<div className="flex gap-1 justify-center sm:justify-end items-center w-fit">
|
||||
<div
|
||||
className="flex items-center btn px-2 btn-ghost rounded-full"
|
||||
onClick={() => setEditCollectionSharingModal(true)}
|
||||
>
|
||||
{collectionOwner.id ? (
|
||||
<ProfilePhoto
|
||||
src={collectionOwner.image || undefined}
|
||||
name={collectionOwner.name}
|
||||
/>
|
||||
) : undefined}
|
||||
{collection.members
|
||||
.sort((a, b) => (a.userId as number) - (b.userId as number))
|
||||
.map((e, i) => {
|
||||
return (
|
||||
<ProfilePhoto
|
||||
key={i}
|
||||
src={e.user.image ? e.user.image : undefined}
|
||||
className="-ml-3"
|
||||
name={e.user.name}
|
||||
/>
|
||||
);
|
||||
})
|
||||
.slice(0, 3)}
|
||||
{collection.members.length - 3 > 0 ? (
|
||||
<div className={`avatar drop-shadow-md placeholder -ml-3`}>
|
||||
<div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
|
||||
<span>+{collection.members.length - 3}</span>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<p className="text-neutral text-sm">
|
||||
{collection.members.length > 0 &&
|
||||
collection.members.length === 1
|
||||
? t("by_author_and_other", {
|
||||
author: collectionOwner.name,
|
||||
count: collection.members.length,
|
||||
<div className="mt-3">
|
||||
<div className={`min-w-[15rem]`}>
|
||||
<div className="flex gap-1 justify-center sm:justify-end items-center w-fit">
|
||||
<div
|
||||
className="flex items-center btn px-2 btn-ghost rounded-full"
|
||||
onClick={() => setEditCollectionSharingModal(true)}
|
||||
>
|
||||
{collectionOwner.id && (
|
||||
<ProfilePhoto
|
||||
src={collectionOwner.image || undefined}
|
||||
name={collectionOwner.name}
|
||||
/>
|
||||
)}
|
||||
{collection.members
|
||||
.sort((a, b) => (a.userId as number) - (b.userId as number))
|
||||
.map((e, i) => {
|
||||
return (
|
||||
<ProfilePhoto
|
||||
key={i}
|
||||
src={e.user.image ? e.user.image : undefined}
|
||||
className="-ml-3"
|
||||
name={e.user.name}
|
||||
/>
|
||||
);
|
||||
})
|
||||
: collection.members.length > 0 &&
|
||||
collection.members.length !== 1
|
||||
? t("by_author_and_others", {
|
||||
.slice(0, 3)}
|
||||
{collection.members.length - 3 > 0 && (
|
||||
<div className={`avatar drop-shadow-md placeholder -ml-3`}>
|
||||
<div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
|
||||
<span>+{collection.members.length - 3}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<p className="text-neutral text-sm">
|
||||
{collection.members.length > 0 &&
|
||||
collection.members.length === 1
|
||||
? t("by_author_and_other", {
|
||||
author: collectionOwner.name,
|
||||
count: collection.members.length,
|
||||
})
|
||||
: t("by_author", {
|
||||
author: collectionOwner.name,
|
||||
})}
|
||||
</p>
|
||||
: collection.members.length > 0 &&
|
||||
collection.members.length !== 1
|
||||
? t("by_author_and_others", {
|
||||
author: collectionOwner.name,
|
||||
count: collection.members.length,
|
||||
})
|
||||
: t("by_author", {
|
||||
author: collectionOwner.name,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="mt-5">{collection.description}</p>
|
||||
<p className="mt-5">{collection.description}</p>
|
||||
|
||||
<div className="divider mt-5 mb-0"></div>
|
||||
<div className="divider mt-5 mb-0"></div>
|
||||
|
||||
<div className="flex mb-5 mt-10 flex-col gap-5">
|
||||
<LinkListOptions
|
||||
t={t}
|
||||
viewMode={viewMode}
|
||||
setViewMode={setViewMode}
|
||||
sortBy={sortBy}
|
||||
setSortBy={setSortBy}
|
||||
searchFilter={searchFilter}
|
||||
setSearchFilter={setSearchFilter}
|
||||
>
|
||||
<SearchBar
|
||||
placeholder={
|
||||
collection._count?.links === 1
|
||||
? t("search_count_link", {
|
||||
count: collection._count?.links,
|
||||
})
|
||||
: t("search_count_links", {
|
||||
count: collection._count?.links,
|
||||
})
|
||||
<div className="flex mb-5 mt-10 flex-col gap-5">
|
||||
<LinkListOptions
|
||||
t={t}
|
||||
viewMode={viewMode}
|
||||
setViewMode={setViewMode}
|
||||
sortBy={sortBy}
|
||||
setSortBy={setSortBy}
|
||||
searchFilter={searchFilter}
|
||||
setSearchFilter={setSearchFilter}
|
||||
>
|
||||
<SearchBar
|
||||
placeholder={
|
||||
collection._count?.links === 1
|
||||
? t("search_count_link", {
|
||||
count: collection._count?.links,
|
||||
})
|
||||
: t("search_count_links", {
|
||||
count: collection._count?.links,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</LinkListOptions>
|
||||
{tags && tags[0] && (
|
||||
<div className="flex gap-2 mt-2 mb-6 flex-wrap">
|
||||
<button
|
||||
className="max-w-full"
|
||||
onClick={() => handleTagSelection(undefined)}
|
||||
>
|
||||
<div
|
||||
className={`${
|
||||
!router.query.q
|
||||
? "bg-primary/20"
|
||||
: "bg-neutral-content/20 hover:bg-neutral/20"
|
||||
} duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 rounded-md h-8`}
|
||||
>
|
||||
<p className="truncate px-3">{t("all_links")}</p>
|
||||
</div>
|
||||
</button>
|
||||
{tags
|
||||
.map((t) => t.name)
|
||||
.filter((item, pos, self) => self.indexOf(item) === pos)
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.map((e, i) => {
|
||||
const active = router.query.q === e;
|
||||
return (
|
||||
<button
|
||||
className="max-w-full"
|
||||
key={i}
|
||||
onClick={() => handleTagSelection(e)}
|
||||
>
|
||||
<div
|
||||
className={`${
|
||||
active
|
||||
? "bg-primary/20"
|
||||
: "bg-neutral-content/20 hover:bg-neutral/20"
|
||||
} duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 rounded-md h-8`}
|
||||
>
|
||||
<i className="bi-hash text-2xl text-primary drop-shadow"></i>
|
||||
<p className="truncate pr-3">{e}</p>
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
<Links
|
||||
links={
|
||||
links?.map((e, i) => {
|
||||
const linkWithCollectionData = {
|
||||
...e,
|
||||
collection: collection, // Append collection data
|
||||
};
|
||||
return linkWithCollectionData;
|
||||
}) as any
|
||||
}
|
||||
layout={viewMode}
|
||||
placeholderCount={1}
|
||||
useData={data}
|
||||
/>
|
||||
</LinkListOptions>
|
||||
{!data.isLoading && links && !links[0] && (
|
||||
<p>{t("nothing_found")}</p>
|
||||
)}
|
||||
|
||||
<Links
|
||||
links={
|
||||
links?.map((e, i) => {
|
||||
const linkWithCollectionData = {
|
||||
...e,
|
||||
collection: collection, // Append collection data
|
||||
};
|
||||
return linkWithCollectionData;
|
||||
}) as any
|
||||
}
|
||||
layout={viewMode}
|
||||
placeholderCount={1}
|
||||
useData={data}
|
||||
/>
|
||||
{!data.isLoading && links && !links[0] && <p>{t("nothing_found")}</p>}
|
||||
|
||||
{/* <p className="text-center text-neutral">
|
||||
{/* <p className="text-center text-neutral">
|
||||
List created with <span className="text-black">Linkwarden.</span>
|
||||
</p> */}
|
||||
</div>
|
||||
</div>
|
||||
{editCollectionSharingModal && (
|
||||
<EditCollectionSharingModal
|
||||
onClose={() => setEditCollectionSharingModal(false)}
|
||||
activeCollection={collection}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{editCollectionSharingModal ? (
|
||||
<EditCollectionSharingModal
|
||||
onClose={() => setEditCollectionSharingModal(false)}
|
||||
activeCollection={collection}
|
||||
/>
|
||||
) : undefined}
|
||||
</div>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
export { getServerSideProps };
|
||||
|
||||
@@ -1,63 +1,70 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import {
|
||||
ArchivedFormat,
|
||||
LinkIncludingShortenedCollectionAndTags,
|
||||
} from "@/types/global";
|
||||
import { ArchivedFormat } from "@/types/global";
|
||||
import ReadableView from "@/components/ReadableView";
|
||||
import getServerSideProps from "@/lib/client/getServerSideProps";
|
||||
import { useGetLink, useLinks } from "@/hooks/store/links";
|
||||
import { useGetLink } from "@/hooks/store/links";
|
||||
import clsx from "clsx";
|
||||
|
||||
export default function Index() {
|
||||
const { links } = useLinks();
|
||||
const getLink = useGetLink();
|
||||
|
||||
const [link, setLink] = useState<LinkIncludingShortenedCollectionAndTags>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchLink = async () => {
|
||||
if (router.query.id) {
|
||||
await getLink.mutateAsync(Number(router.query.id));
|
||||
}
|
||||
};
|
||||
|
||||
fetchLink();
|
||||
if (router.query.id) {
|
||||
getLink.mutateAsync({ id: Number(router.query.id), isPublicRoute: true });
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (links && links[0])
|
||||
setLink(links.find((e) => e.id === Number(router.query.id)));
|
||||
}, [links]);
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<div className={clsx(getLink.isPending ? "flex h-screen" : "relative")}>
|
||||
{/* <div className="fixed left-1/2 transform -translate-x-1/2 w-fit py-1 px-3 bg-base-200 border border-neutral-content rounded-md">
|
||||
Readable
|
||||
</div> */}
|
||||
{link && Number(router.query.format) === ArchivedFormat.readability && (
|
||||
<ReadableView link={link} />
|
||||
)}
|
||||
{link && Number(router.query.format) === ArchivedFormat.pdf && (
|
||||
{getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.readability ? (
|
||||
<ReadableView link={getLink.data} />
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.monolith ? (
|
||||
<iframe
|
||||
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.pdf}`}
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.monolith}`}
|
||||
className="w-full h-screen border-none"
|
||||
></iframe>
|
||||
)}
|
||||
{link && Number(router.query.format) === ArchivedFormat.png && (
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.pdf ? (
|
||||
<iframe
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.pdf}`}
|
||||
className="w-full h-screen border-none"
|
||||
></iframe>
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.png ? (
|
||||
<img
|
||||
alt=""
|
||||
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.png}`}
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.png}`}
|
||||
className="w-fit mx-auto"
|
||||
/>
|
||||
)}
|
||||
{link && Number(router.query.format) === ArchivedFormat.jpeg && (
|
||||
) : getLink.data?.id &&
|
||||
Number(router.query.format) === ArchivedFormat.jpeg ? (
|
||||
<img
|
||||
alt=""
|
||||
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}`}
|
||||
src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.jpeg}`}
|
||||
className="w-fit mx-auto"
|
||||
/>
|
||||
) : getLink.error ? (
|
||||
<p>404 - Not found</p>
|
||||
) : (
|
||||
<div className="max-w-3xl p-5 m-auto w-full flex flex-col items-center gap-5">
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-full mr-auto h-4 skeleton rounded-md"></div>
|
||||
<div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
+76
-35
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, ChangeEvent } from "react";
|
||||
import { AccountSettings } from "@/types/global";
|
||||
import { toast } from "react-hot-toast";
|
||||
import SettingsLayout from "@/layouts/SettingsLayout";
|
||||
@@ -17,6 +17,7 @@ import { i18n } from "next-i18next.config";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import getServerSideProps from "@/lib/client/getServerSideProps";
|
||||
import { useUpdateUser, useUser } from "@/hooks/store/user";
|
||||
import { z } from "zod";
|
||||
|
||||
const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER;
|
||||
|
||||
@@ -55,8 +56,10 @@ export default function Account() {
|
||||
if (!objectIsEmpty(account)) setUser({ ...account });
|
||||
}, [account]);
|
||||
|
||||
const handleImageUpload = async (e: any) => {
|
||||
const file: File = e.target.files[0];
|
||||
const handleImageUpload = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return toast.error(t("image_upload_no_file_error"));
|
||||
|
||||
const fileExtension = file.name.split(".").pop()?.toLowerCase();
|
||||
const allowedExtensions = ["png", "jpeg", "jpg"];
|
||||
if (allowedExtensions.includes(fileExtension as string)) {
|
||||
@@ -78,6 +81,16 @@ export default function Account() {
|
||||
};
|
||||
|
||||
const submit = async (password?: string) => {
|
||||
if (!/^[a-z0-9_-]{3,50}$/.test(user.username || "")) {
|
||||
return toast.error(t("username_invalid_guide"));
|
||||
}
|
||||
|
||||
const emailSchema = z.string().trim().email().toLowerCase();
|
||||
const emailValidation = emailSchema.safeParse(user.email || "");
|
||||
if (!emailValidation.success) {
|
||||
return toast.error(t("email_invalid"));
|
||||
}
|
||||
|
||||
setSubmitLoader(true);
|
||||
|
||||
const load = toast.loading(t("applying_settings"));
|
||||
@@ -88,13 +101,8 @@ export default function Account() {
|
||||
password: password ? password : undefined,
|
||||
},
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
if (data.response.email !== user.email) {
|
||||
toast.success(t("email_change_request"));
|
||||
setEmailChangeVerificationModal(false);
|
||||
}
|
||||
},
|
||||
onSettled: (data, error) => {
|
||||
setSubmitLoader(false);
|
||||
toast.dismiss(load);
|
||||
|
||||
if (error) {
|
||||
@@ -111,39 +119,72 @@ export default function Account() {
|
||||
}
|
||||
);
|
||||
|
||||
setSubmitLoader(false);
|
||||
if (user.locale !== account.locale) {
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
const importBookmarks = async (e: any, format: MigrationFormat) => {
|
||||
setSubmitLoader(true);
|
||||
const file: File = e.target.files[0];
|
||||
const importBookmarks = async (
|
||||
e: React.ChangeEvent<HTMLInputElement>,
|
||||
format: MigrationFormat
|
||||
) => {
|
||||
const file: File | null = e.target.files && e.target.files[0];
|
||||
|
||||
if (file) {
|
||||
var reader = new FileReader();
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file, "UTF-8");
|
||||
reader.onload = async function (e) {
|
||||
const load = toast.loading(t("importing_bookmarks"));
|
||||
const load = toast.loading("Importing...");
|
||||
|
||||
const request: string = e.target?.result as string;
|
||||
const body: MigrationRequest = { format, data: request };
|
||||
const response = await fetch("/api/v1/migration", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await response.json();
|
||||
toast.dismiss(load);
|
||||
if (response.ok) {
|
||||
toast.success(t("import_success"));
|
||||
|
||||
const body: MigrationRequest = {
|
||||
format,
|
||||
data: request,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/v1/migration", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
toast.dismiss(load);
|
||||
|
||||
toast.error(
|
||||
errorData.response ||
|
||||
"Failed to import bookmarks. Please try again."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await response.json();
|
||||
toast.dismiss(load);
|
||||
toast.success("Imported the Bookmarks! Reloading the page...");
|
||||
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 2000);
|
||||
} else {
|
||||
toast.error(data.response as string);
|
||||
} catch (error) {
|
||||
console.error("Request failed", error);
|
||||
toast.dismiss(load);
|
||||
toast.error(
|
||||
"An error occurred while importing bookmarks. Please check the logs for more info."
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = function (e) {
|
||||
console.log("Error:", e);
|
||||
console.log("Error reading file:", e);
|
||||
toast.error(
|
||||
"Failed to read the file. Please make sure the file is correct and try again."
|
||||
);
|
||||
};
|
||||
}
|
||||
setSubmitLoader(false);
|
||||
};
|
||||
|
||||
const [whitelistedUsersTextbox, setWhiteListedUsersTextbox] = useState("");
|
||||
@@ -190,16 +231,17 @@ export default function Account() {
|
||||
onChange={(e) => setUser({ ...user, username: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
{emailEnabled ? (
|
||||
{emailEnabled && (
|
||||
<div>
|
||||
<p className="mb-2">{t("email")}</p>
|
||||
<TextInput
|
||||
value={user.email || ""}
|
||||
type="email"
|
||||
className="bg-base-200"
|
||||
onChange={(e) => setUser({ ...user, email: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
) : undefined}
|
||||
)}
|
||||
<div>
|
||||
<p className="mb-2">{t("language")}</p>
|
||||
<select
|
||||
@@ -437,9 +479,8 @@ export default function Account() {
|
||||
|
||||
<p>
|
||||
{t("delete_account_warning")}
|
||||
{process.env.NEXT_PUBLIC_STRIPE
|
||||
? " " + t("cancel_subscription_notice")
|
||||
: undefined}
|
||||
{process.env.NEXT_PUBLIC_STRIPE &&
|
||||
" " + t("cancel_subscription_notice")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -448,14 +489,14 @@ export default function Account() {
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{emailChangeVerificationModal ? (
|
||||
{emailChangeVerificationModal && (
|
||||
<EmailChangeVerificationModal
|
||||
onClose={() => setEmailChangeVerificationModal(false)}
|
||||
onSubmit={submit}
|
||||
oldEmail={account.email || ""}
|
||||
newEmail={user.email || ""}
|
||||
/>
|
||||
) : undefined}
|
||||
)}
|
||||
</SettingsLayout>
|
||||
);
|
||||
}
|
||||
|
||||
+231
-2
@@ -1,17 +1,57 @@
|
||||
import SettingsLayout from "@/layouts/SettingsLayout";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect } from "react";
|
||||
import InviteModal from "@/components/ModalContent/InviteModal";
|
||||
import { User as U } from "@prisma/client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import getServerSideProps from "@/lib/client/getServerSideProps";
|
||||
import { useUsers } from "@/hooks/store/admin/users";
|
||||
import DeleteUserModal from "@/components/ModalContent/DeleteUserModal";
|
||||
import { useUser } from "@/hooks/store/user";
|
||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||
import clsx from "clsx";
|
||||
import { signIn } from "next-auth/react";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
interface User extends U {
|
||||
subscriptions: {
|
||||
active: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
type UserModal = {
|
||||
isOpen: boolean;
|
||||
userId: number | null;
|
||||
};
|
||||
|
||||
export default function Billing() {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data: account } = useUser();
|
||||
const { data: users = [] } = useUsers();
|
||||
|
||||
useEffect(() => {
|
||||
if (!process.env.NEXT_PUBLIC_STRIPE) router.push("/settings/profile");
|
||||
if (!process.env.NEXT_PUBLIC_STRIPE || account.parentSubscriptionId)
|
||||
router.push("/settings/account");
|
||||
}, []);
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [filteredUsers, setFilteredUsers] = useState<User[]>();
|
||||
|
||||
useEffect(() => {
|
||||
if (users.length > 0) {
|
||||
setFilteredUsers(users);
|
||||
}
|
||||
}, [users]);
|
||||
|
||||
const [deleteUserModal, setDeleteUserModal] = useState<UserModal>({
|
||||
isOpen: false,
|
||||
userId: null,
|
||||
});
|
||||
|
||||
const [inviteModal, setInviteModal] = useState(false);
|
||||
|
||||
return (
|
||||
<SettingsLayout>
|
||||
<p className="capitalize text-3xl font-thin inline">
|
||||
@@ -40,6 +80,195 @@ export default function Billing() {
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 w-full rounded-md h-8 mt-5">
|
||||
<p className="truncate w-full pr-7 text-3xl font-thin">
|
||||
{t("manage_seats")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="divider my-3"></div>
|
||||
|
||||
<div className="flex items-center justify-between gap-2 mb-3 relative">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="search-box"
|
||||
className="inline-flex items-center w-fit absolute left-1 pointer-events-none rounded-md p-1 text-primary"
|
||||
>
|
||||
<i className="bi-search"></i>
|
||||
</label>
|
||||
|
||||
<input
|
||||
id="search-box"
|
||||
type="text"
|
||||
placeholder={t("search_users")}
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
setSearchQuery(e.target.value);
|
||||
|
||||
if (users) {
|
||||
setFilteredUsers(
|
||||
users.filter((user: any) =>
|
||||
JSON.stringify(user)
|
||||
.toLowerCase()
|
||||
.includes(e.target.value.toLowerCase())
|
||||
)
|
||||
);
|
||||
}
|
||||
}}
|
||||
className="border border-neutral-content bg-base-200 focus:border-primary py-1 rounded-md pl-9 pr-2 w-full max-w-[15rem] md:w-[15rem] md:max-w-full duration-200 outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<div
|
||||
onClick={() => setInviteModal(true)}
|
||||
className="flex items-center btn btn-accent dark:border-violet-400 text-white btn-sm px-2 h-[2.15rem] relative"
|
||||
>
|
||||
<p>{t("invite_user")}</p>
|
||||
<i className="bi-plus text-2xl"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border rounded-md shadow border-neutral-content">
|
||||
<table className="table bg-base-300 rounded-md">
|
||||
<thead>
|
||||
<tr className="sm:table-row hidden border-b-neutral-content">
|
||||
{process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && (
|
||||
<th>{t("email")}</th>
|
||||
)}
|
||||
{process.env.NEXT_PUBLIC_STRIPE === "true" && (
|
||||
<th>{t("status")}</th>
|
||||
)}
|
||||
<th>{t("date_added")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filteredUsers?.map((user, index) => (
|
||||
<tr
|
||||
key={index}
|
||||
className={clsx(
|
||||
"group border-b-neutral-content duration-100 w-full relative flex flex-col sm:table-row",
|
||||
user.id !== account.id &&
|
||||
"hover:bg-neutral-content hover:bg-opacity-30"
|
||||
)}
|
||||
>
|
||||
{process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && (
|
||||
<td className="truncate max-w-full" title={user.email || ""}>
|
||||
<p className="sm:hidden block text-neutral text-xs font-bold mb-2">
|
||||
{t("email")}
|
||||
</p>
|
||||
<p>{user.email}</p>
|
||||
</td>
|
||||
)}
|
||||
{process.env.NEXT_PUBLIC_STRIPE === "true" && (
|
||||
<td>
|
||||
<p className="sm:hidden block text-neutral text-xs font-bold mb-2">
|
||||
{t("status")}
|
||||
</p>
|
||||
{user.emailVerified ? (
|
||||
<p className="font-bold px-2 bg-green-600 text-white rounded-md w-fit">
|
||||
{t("active")}
|
||||
</p>
|
||||
) : (
|
||||
<p className="font-bold px-2 bg-neutral-content rounded-md w-fit">
|
||||
{t("pending")}
|
||||
</p>
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
<td>
|
||||
<p className="sm:hidden block text-neutral text-xs font-bold mb-2">
|
||||
{t("date_added")}
|
||||
</p>
|
||||
<p className="whitespace-nowrap">
|
||||
{new Date(user.createdAt).toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
})}
|
||||
</p>
|
||||
</td>
|
||||
{user.id !== account.id && (
|
||||
<td className="relative">
|
||||
<div
|
||||
className={`dropdown dropdown-bottom font-normal dropdown-end absolute right-[0.35rem] top-[0.35rem]`}
|
||||
>
|
||||
<div
|
||||
tabIndex={0}
|
||||
role="button"
|
||||
onMouseDown={dropdownTriggerer}
|
||||
className="btn btn-ghost btn-sm btn-square duration-100"
|
||||
>
|
||||
<i
|
||||
className={"bi bi-three-dots text-lg text-neutral"}
|
||||
></i>
|
||||
</div>
|
||||
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-box mt-1">
|
||||
{!user.emailVerified ? (
|
||||
<li>
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => {
|
||||
(
|
||||
document?.activeElement as HTMLElement
|
||||
)?.blur();
|
||||
signIn("invite", {
|
||||
email: user.email,
|
||||
callbackUrl: "/member-onboarding",
|
||||
redirect: false,
|
||||
}).then(() =>
|
||||
toast.success(t("resend_invite_success"))
|
||||
);
|
||||
}}
|
||||
className="whitespace-nowrap"
|
||||
>
|
||||
{t("resend_invite")}
|
||||
</div>
|
||||
</li>
|
||||
) : undefined}
|
||||
<li>
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => {
|
||||
(document?.activeElement as HTMLElement)?.blur();
|
||||
setDeleteUserModal({
|
||||
isOpen: true,
|
||||
userId: user.id,
|
||||
});
|
||||
}}
|
||||
className="whitespace-nowrap"
|
||||
>
|
||||
{t("remove_user")}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p className="text-sm text-center font-bold mt-3">
|
||||
{t(
|
||||
account?.subscription?.quantity === 1
|
||||
? "seat_purchased"
|
||||
: "seats_purchased",
|
||||
{ count: account?.subscription?.quantity }
|
||||
)}
|
||||
</p>
|
||||
{inviteModal && <InviteModal onClose={() => setInviteModal(false)} />}
|
||||
{deleteUserModal.isOpen && deleteUserModal.userId && (
|
||||
<DeleteUserModal
|
||||
onClose={() => setDeleteUserModal({ isOpen: false, userId: null })}
|
||||
userId={deleteUserModal.userId}
|
||||
/>
|
||||
)}
|
||||
</SettingsLayout>
|
||||
);
|
||||
}
|
||||
|
||||
+8
-8
@@ -9,8 +9,6 @@ import getServerSideProps from "@/lib/client/getServerSideProps";
|
||||
import { Trans, useTranslation } from "next-i18next";
|
||||
import { useUser } from "@/hooks/store/user";
|
||||
|
||||
const stripeEnabled = process.env.NEXT_PUBLIC_STRIPE === "true";
|
||||
|
||||
export default function Subscribe() {
|
||||
const { t } = useTranslation();
|
||||
const [submitLoader, setSubmitLoader] = useState(false);
|
||||
@@ -23,13 +21,13 @@ export default function Subscribe() {
|
||||
const { data: user = {} } = useUser();
|
||||
|
||||
useEffect(() => {
|
||||
const hasInactiveSubscription =
|
||||
user.id && !user.subscription?.active && stripeEnabled;
|
||||
|
||||
if (session.status === "authenticated" && !hasInactiveSubscription) {
|
||||
if (
|
||||
session.status === "authenticated" &&
|
||||
user.id &&
|
||||
(user?.subscription?.active || user.parentSubscription?.active)
|
||||
)
|
||||
router.push("/dashboard");
|
||||
}
|
||||
}, [session.status]);
|
||||
}, [session.status, user]);
|
||||
|
||||
async function submit() {
|
||||
setSubmitLoader(true);
|
||||
@@ -40,6 +38,8 @@ export default function Subscribe() {
|
||||
const data = await res.json();
|
||||
|
||||
router.push(data.response);
|
||||
|
||||
toast.dismiss(redirectionToast);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user