From 2bbf9751ad95721b4e7f4483ae83124875f5c854 Mon Sep 17 00:00:00 2001 From: Shahrad Elahi Date: Tue, 3 Oct 2023 10:50:03 +0330 Subject: [PATCH] code split and removes a silly mistake --- src/pages/[serverId]/index.tsx | 6 +-- src/pages/index.tsx | 51 ++----------------- src/ui/icons/ServerIcon.tsx | 36 +++++++++++++ src/ui/icons/TorOnionIcon.tsx | 16 ++++++ src/ui/{Modal => modal}/CreateClientModal.tsx | 8 +-- src/ui/{Modal => modal}/CreateServerModal.tsx | 10 ++-- src/ui/{Modal => modal}/QRCodeModal.tsx | 2 +- src/ui/{Modal => modal}/SmartModal.tsx | 0 src/ui/pages/PageHeader.tsx | 2 +- 9 files changed, 65 insertions(+), 66 deletions(-) create mode 100644 src/ui/icons/ServerIcon.tsx create mode 100644 src/ui/icons/TorOnionIcon.tsx rename src/ui/{Modal => modal}/CreateClientModal.tsx (94%) rename src/ui/{Modal => modal}/CreateServerModal.tsx (96%) rename src/ui/{Modal => modal}/QRCodeModal.tsx (93%) rename src/ui/{Modal => modal}/SmartModal.tsx (100%) diff --git a/src/pages/[serverId]/index.tsx b/src/pages/[serverId]/index.tsx index 87c9d2d..9b34ce2 100644 --- a/src/pages/[serverId]/index.tsx +++ b/src/pages/[serverId]/index.tsx @@ -9,10 +9,10 @@ import useSWRMutation from "swr/mutation"; import { useRouter } from "next/router"; import { MiddleEllipsis } from "@ui/MiddleEllipsis"; import StatusBadge from "@ui/StatusBadge"; -import { SmartModalRef } from "@ui/Modal/SmartModal"; -import CreateClientModal from "@ui/Modal/CreateClientModal"; +import { SmartModalRef } from "@ui/modal/SmartModal"; +import CreateClientModal from "@ui/modal/CreateClientModal"; import { twMerge } from "tailwind-merge"; -import QRCodeModal from "@ui/Modal/QRCodeModal"; +import QRCodeModal from "@ui/modal/QRCodeModal"; import { getPeerConf } from "@lib/wireguard-utils"; import EditableText from "@ui/EditableText"; import { RLS_NAME_INPUT } from "@lib/form-rules"; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index dde964e..9a0b7d5 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -3,19 +3,18 @@ import { Button, Card, List } from "antd"; import BasePage from "@ui/pages/BasePage"; import { APIResponse, WgServer } from "@lib/typings"; import { PlusOutlined } from "@ant-design/icons"; -import Image, { ImageProps } from "next/image"; import Link from "next/link"; import PageRouter from "@ui/pages/PageRouter"; import useSWR from "swr"; -import { SmartModalRef } from "@ui/Modal/SmartModal"; -import { twMerge } from "tailwind-merge"; -import CreateServerModal from "@ui/Modal/CreateServerModal"; +import { SmartModalRef } from "@ui/modal/SmartModal"; +import CreateServerModal from "@ui/modal/CreateServerModal"; import StatusBadge from "@ui/StatusBadge"; import EditableText from "@ui/EditableText"; import useSWRMutation from "swr/mutation"; import { UPDATE_SERVER } from "@lib/swr-fetch"; import { RLS_NAME_INPUT } from "@lib/form-rules"; import CopiableWrapper from "@ui/CopiableWrapper"; +import ServerIcon from "@ui/icons/ServerIcon"; export default function Home() { const { data, error, isLoading, mutate } = useSWR( @@ -133,47 +132,3 @@ function ServerListItem(props: ServerListItemProps) { ) } -type ServerIconProps = { - type: WgServer['type'] - className?: string -} - -function ServerIcon(props: ServerIconProps) { - return ( -
-
- {'VPS'} - {props.type !== 'direct' && ( -
- {props.type === 'tor' && ( - {'Tor'} - )} -
- )} -
-
- ) -} - -export function TorOnion(props: Omit) { - return ( - {'Tor'} - ) -} diff --git a/src/ui/icons/ServerIcon.tsx b/src/ui/icons/ServerIcon.tsx new file mode 100644 index 0000000..a9fb931 --- /dev/null +++ b/src/ui/icons/ServerIcon.tsx @@ -0,0 +1,36 @@ +import { WgServer } from "@lib/typings"; +import { twMerge } from "tailwind-merge"; +import Image from "next/image"; +import React from "react"; + +export interface ServerIconProps { + type: WgServer['type'] + className?: string +} + +export default function ServerIcon(props: ServerIconProps) { + return ( +
+
+ {'VPS'} + {props.type !== 'direct' && ( +
+ {props.type === 'tor' && ( + {'Tor'} + )} +
+ )} +
+
+ ) +} diff --git a/src/ui/icons/TorOnionIcon.tsx b/src/ui/icons/TorOnionIcon.tsx new file mode 100644 index 0000000..91d6932 --- /dev/null +++ b/src/ui/icons/TorOnionIcon.tsx @@ -0,0 +1,16 @@ +import Image, { ImageProps } from "next/image"; +import { twMerge } from "tailwind-merge"; +import React from "react"; + +export default function TorOnion(props: Omit) { + return ( + {'Tor'} + ) +} diff --git a/src/ui/Modal/CreateClientModal.tsx b/src/ui/modal/CreateClientModal.tsx similarity index 94% rename from src/ui/Modal/CreateClientModal.tsx rename to src/ui/modal/CreateClientModal.tsx index 1ccd89c..81c0de2 100644 --- a/src/ui/Modal/CreateClientModal.tsx +++ b/src/ui/modal/CreateClientModal.tsx @@ -1,5 +1,5 @@ import React from "react"; -import SmartModal, { SmartModalRef } from "@ui/Modal/SmartModal"; +import SmartModal, { SmartModalRef } from "@ui/modal/SmartModal"; import { Button, Form, Input, notification } from "antd"; import { z } from "zod"; import { APIResponse } from "@lib/typings"; @@ -50,11 +50,7 @@ const CreateClientModal = React.forwardRef< props.refreshTrigger() notificationApi.success({ message: 'Success', - description: ( -
- hi -
- ) + description: 'Client has been created!' }) innerRef.current?.close() form?.resetFields() diff --git a/src/ui/Modal/CreateServerModal.tsx b/src/ui/modal/CreateServerModal.tsx similarity index 96% rename from src/ui/Modal/CreateServerModal.tsx rename to src/ui/modal/CreateServerModal.tsx index bfa254d..4d876b5 100644 --- a/src/ui/Modal/CreateServerModal.tsx +++ b/src/ui/modal/CreateServerModal.tsx @@ -1,13 +1,13 @@ import React from "react"; -import SmartModal, { SmartModalRef } from "@ui/Modal/SmartModal"; +import SmartModal, { SmartModalRef } from "@ui/modal/SmartModal"; import { Button, Form, Input, notification, Segmented } from "antd"; -import { TorOnion } from "@/pages"; import { z } from "zod"; import { APIResponse } from "@lib/typings"; import useSWRMutation from "swr/mutation"; import { isPrivateIP } from "@lib/utils"; import { AddressSchema, DnsSchema, MtuSchema, NameSchema, PortSchema, TypeSchema } from "@lib/schemas/WireGuard"; import { zodErrorMessage } from "@lib/zod"; +import TorOnion from "@ui/icons/TorOnionIcon"; type CreateServerModalProps = { refreshTrigger: () => void @@ -51,11 +51,7 @@ const CreateServerModal = React.forwardRef< onSuccess: () => { notificationApi.success({ message: 'Success', - description: ( -
- hi -
- ) + description: 'Server has been created!' }) innerRef.current?.close() form?.resetFields() diff --git a/src/ui/Modal/QRCodeModal.tsx b/src/ui/modal/QRCodeModal.tsx similarity index 93% rename from src/ui/Modal/QRCodeModal.tsx rename to src/ui/modal/QRCodeModal.tsx index e37699d..59d1901 100644 --- a/src/ui/Modal/QRCodeModal.tsx +++ b/src/ui/modal/QRCodeModal.tsx @@ -1,5 +1,5 @@ import React from "react"; -import SmartModal, { SmartModalRef } from "@ui/Modal/SmartModal"; +import SmartModal, { SmartModalRef } from "@ui/modal/SmartModal"; import { QRCodeCanvas } from "qrcode.react"; import { SHA1 } from "crypto-js"; diff --git a/src/ui/Modal/SmartModal.tsx b/src/ui/modal/SmartModal.tsx similarity index 100% rename from src/ui/Modal/SmartModal.tsx rename to src/ui/modal/SmartModal.tsx diff --git a/src/ui/pages/PageHeader.tsx b/src/ui/pages/PageHeader.tsx index aa23b98..7c1cee0 100644 --- a/src/ui/pages/PageHeader.tsx +++ b/src/ui/pages/PageHeader.tsx @@ -24,7 +24,7 @@ export default function PageHeader(props: PageHeaderProps) { title={'Giv me a star on Github'} > {'Giv