Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for QR code when adding network #292

Merged
merged 6 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"next-themes": "^0.2.1",
"nodemailer": "^6.9.9",
"pug": "^3.0.2",
"qrcode.react": "^3.1.0",
"react": "18.2.0",
"react-copy-to-clipboard": "^5.1.0",
"react-datepicker": "^4.21.0",
Expand Down
53 changes: 53 additions & 0 deletions src/components/networkByIdPage/networkQrCode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useTheme } from "next-themes";
import { QRCodeSVG } from "qrcode.react";
import React, { useEffect, useState } from "react";
import { CopyToClipboard } from "react-copy-to-clipboard";
import toast from "react-hot-toast";
import daisyuiColors from "daisyui/src/theming/themes";
import { useTranslations } from "next-intl";

interface IProps {
networkId: string;
}

const urlBuilder = (networkId: string) => {
return `https://joinzt.com/addnetwork?nwid=${networkId}&v=1`;
};

const NetworkQrCode = ({ networkId }: IProps) => {
const t = useTranslations("networkById");
const [themeRGBColor, setThemeRGBColor] = useState("");
const { theme } = useTheme();

useEffect(() => {
setThemeRGBColor(daisyuiColors[theme]?.primary);
}, [theme]);

return (
<CopyToClipboard
text={urlBuilder(networkId)}
onCopy={() =>
toast.success(
t("copyToClipboard.success", {
element: urlBuilder(networkId),
}),
{
id: "copyNwid",
},
)
}
title={t("copyToClipboard.title")}
>
<QRCodeSVG
value={urlBuilder(networkId)}
size={100}
bgColor={themeRGBColor}
fgColor={"#000000"}
level={"M"}
includeMargin={true}
/>
</CopyToClipboard>
);
};

export default NetworkQrCode;
10 changes: 8 additions & 2 deletions src/pages/central/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { NetworkDns } from "~/components/networkByIdPage/networkDns";
import { getServerSideProps } from "~/server/getServerSideProps";
import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket";
import NetworkLoadingSkeleton from "~/components/shared/networkLoadingSkeleton";
import NetworkQrCode from "~/components/networkByIdPage/networkQrCode";

const HeadSection = ({ title }: { title: string }) => (
<Head>
Expand Down Expand Up @@ -91,7 +92,7 @@ const CentralNetworkById = ({ orgIds }) => {
<div>
<HeadSection title={pageTitle} />
<div className="w-5/5 mx-auto flex flex-row flex-wrap justify-between space-y-10 p-4 text-sm sm:w-5/6 sm:p-10 md:text-base xl:space-y-0">
<div className="w-5/5 h-fit w-full xl:w-2/6 ">
<div className="grid grid-cols-1 xl:grid-cols-[1fr,auto,1fr] gap-10">
<div className="flex flex-col space-y-3 sm:space-y-0">
<div className="flex flex-col justify-between sm:flex-row">
<span className="font-semibold">{t("networkId")}</span>
Expand All @@ -118,8 +119,13 @@ const CentralNetworkById = ({ orgIds }) => {
<NetworkName central />
<NetworkDescription central />
</div>
<div className="cursor-pointer">
<NetworkQrCode networkId={network?.nwid} />
</div>
<div>
<NetworkPrivatePublic central />
</div>
</div>
<NetworkPrivatePublic central />
</div>
<div className="w-5/5 mx-auto flex px-4 text-sm sm:w-5/6 sm:px-10 md:text-base">
<div className="flex flex-col justify-between space-y-3 whitespace-nowrap lg:flex-row lg:space-x-3 lg:space-y-0">
Expand Down
14 changes: 9 additions & 5 deletions src/pages/network/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { globalSiteTitle } from "~/utils/global";
import { getServerSideProps } from "~/server/getServerSideProps";
import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket";
import NetworkLoadingSkeleton from "~/components/shared/networkLoadingSkeleton";
import NetworkQrCode from "~/components/networkByIdPage/networkQrCode";

const HeadSection = ({ title }: { title: string }) => (
<Head>
Expand Down Expand Up @@ -122,8 +123,8 @@ const NetworkById = ({ orgIds }: IProps) => {
return (
<div className="animate-fadeIn">
<HeadSection title={pageTitle} />
<div className="w-5/5 mx-auto flex flex-row flex-wrap justify-between space-y-10 p-4 text-sm sm:w-5/6 sm:p-10 md:text-base xl:space-y-0">
<div className="w-5/5 h-fit w-full xl:w-2/6 ">
<div className="w-5/5 mx-auto flex py-10 px-4 text-sm sm:w-5/6 sm:px-10 md:text-base">
<div className="grid grid-cols-1 xl:grid-cols-[1fr,auto,1fr] gap-10">
<div className="flex flex-col space-y-3 sm:space-y-0">
<div className="flex flex-col justify-between sm:flex-row">
<span className="font-semibold">{t("networkId")}</span>
Expand All @@ -150,9 +151,12 @@ const NetworkById = ({ orgIds }: IProps) => {
<NetworkName />
<NetworkDescription />
</div>
</div>
<div>
<NetworkPrivatePublic />
<div className="cursor-pointer">
<NetworkQrCode networkId={network?.nwid} />
</div>
<div>
<NetworkPrivatePublic />
</div>
</div>
</div>
<div className="w-5/5 mx-auto flex px-4 text-sm sm:w-5/6 sm:px-10 md:text-base">
Expand Down
61 changes: 31 additions & 30 deletions src/pages/organization/[orgid]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getServerSideProps } from "~/server/getServerSideProps";
import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket";
import NetworkLoadingSkeleton from "~/components/shared/networkLoadingSkeleton";
import HeadSection from "~/components/shared/metaTags";
import NetworkQrCode from "~/components/networkByIdPage/networkQrCode";

type OrganizationId = {
id: string;
Expand Down Expand Up @@ -115,40 +116,40 @@ const OrganizationNetworkById = ({ orgIds }: IProps) => {
<div className="animate-fadeIn">
<HeadSection title={pageTitle} />
<div className="mx-auto text-sm sm:py-10 md:text-base">
<div className="grid grid-cols-1 xl:grid-cols-2 gap-10">
<div className="grid grid-cols-1 xl:grid-cols-[1fr,auto,1fr] gap-10">
{/* Left section with network ID, name, and description */}
<div className="xl:col-span-1">
<div className="space-y-1">
{/* Network ID */}
<div className="flex flex-col sm:flex-row justify-between">
<span className="font-semibold">{t("networkId")}</span>
<span className="flex items-center">
<CopyToClipboard
text={network?.nwid}
onCopy={() =>
toast.success(
t("copyToClipboard.success", { element: network?.nwid }),
{ id: "copyNwid" },
)
}
title={t("copyToClipboard.title")}
>
<div className="flex cursor-pointer items-center gap-2">
{network?.nwid}
<CopyIcon />
</div>
</CopyToClipboard>
</span>
</div>
{/* Network Name */}
<NetworkName organizationId={organizationId} />
{/* Network Description */}
<NetworkDescription organizationId={organizationId} />
<div className="space-y-1">
{/* Network ID */}
<div className="flex flex-col sm:flex-row justify-between">
<span className="font-semibold">{t("networkId")}</span>
<span className="flex items-center">
<CopyToClipboard
text={network?.nwid}
onCopy={() =>
toast.success(
t("copyToClipboard.success", { element: network?.nwid }),
{ id: "copyNwid" },
)
}
title={t("copyToClipboard.title")}
>
<div className="flex cursor-pointer items-center gap-2">
{network?.nwid}
<CopyIcon />
</div>
</CopyToClipboard>
</span>
</div>
{/* Network Name */}
<NetworkName organizationId={organizationId} />
{/* Network Description */}
<NetworkDescription organizationId={organizationId} />
</div>
<div className="cursor-pointer">
<NetworkQrCode networkId={network?.nwid} />
</div>

{/* Right section with NetworkPrivatePublic */}
<div className="xl:col-span-1">
<div>
<NetworkPrivatePublic organizationId={organizationId} />
</div>
</div>
Expand Down
Loading