From 3e0d422d3d37aa639e50ef4703d4cf7a2de66719 Mon Sep 17 00:00:00 2001 From: pranavmene2000 Date: Tue, 17 Dec 2024 22:26:25 +0530 Subject: [PATCH 1/6] feat: add help and support gateway --- frontend/src/App.tsx | 2 + .../feature/settings/help/SocketIOHealth.tsx | 72 ++++++++ .../feature/settings/help/SupportRequest.tsx | 161 ++++++++++++++++++ .../feature/userSettings/SettingsSidebar.tsx | 15 +- .../src/pages/settings/HelpAndSupport.tsx | 72 ++++++++ 5 files changed, 316 insertions(+), 6 deletions(-) create mode 100644 frontend/src/components/feature/settings/help/SocketIOHealth.tsx create mode 100644 frontend/src/components/feature/settings/help/SupportRequest.tsx create mode 100644 frontend/src/pages/settings/HelpAndSupport.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 210c51fa..ca592689 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -97,6 +97,8 @@ const router = createBrowserRouter( import('./pages/settings/MessageActions/CreateMessageAction')} /> import('./pages/settings/MessageActions/ViewMessageAction')} /> + + import('./pages/settings/HelpAndSupport')} /> }> } /> diff --git a/frontend/src/components/feature/settings/help/SocketIOHealth.tsx b/frontend/src/components/feature/settings/help/SocketIOHealth.tsx new file mode 100644 index 00000000..4e1714e2 --- /dev/null +++ b/frontend/src/components/feature/settings/help/SocketIOHealth.tsx @@ -0,0 +1,72 @@ +import { ErrorCallout } from "@/components/common/Callouts/ErrorCallouts" +import SettingsContentContainer from "@/components/layout/Settings/SettingsContentContainer" +import { Badge, Flex, IconButton, Link, Text } from "@radix-ui/themes" +import clsx from "clsx" +import { FrappeConfig, FrappeContext, useFrappeEventListener } from "frappe-react-sdk" +import { useContext, useEffect, useState } from "react" +import { LuRefreshCcw } from "react-icons/lu" +import { TbReportAnalytics } from "react-icons/tb" + +const SocketIOHealth = () => { + + const { socket } = useContext(FrappeContext) as FrappeConfig + + const [loading, setLoading] = useState(true) + const [socketPingTest, setSocketPingTest] = useState('Fail') + const [socketTransportMode, setSocketTransportMode] = useState('') + + useFrappeEventListener('pong', () => { + setSocketPingTest('Pass') + setLoading(false) + setSocketTransportMode(socket?.io.engine.transport.name) + }) + + const onPingCheck = () => { + setLoading(true) + socket?.emit('ping') + setTimeout(() => { + setLoading(false) + setSocketTransportMode(s => { + if (!s) { + return '' + } + return s + }) + }, 5000) + } + + useEffect(() => { + setTimeout(onPingCheck, 5000); + }, []); + + return ( + + {!loading && socketPingTest === 'Fail' && } + + + Real-time Ping Check: + + {loading ? 'Loading...' : socketPingTest} + {!loading && + + } + + + + {socketTransportMode && + SocketIO Transport Mode: + {socketTransportMode} + } + + System Health Report + + + + ) +} + +export default SocketIOHealth \ No newline at end of file diff --git a/frontend/src/components/feature/settings/help/SupportRequest.tsx b/frontend/src/components/feature/settings/help/SupportRequest.tsx new file mode 100644 index 00000000..bd787bbb --- /dev/null +++ b/frontend/src/components/feature/settings/help/SupportRequest.tsx @@ -0,0 +1,161 @@ +import { Box, Button, Dialog, Flex, RadioCards, Text, TextArea, TextField } from "@radix-ui/themes" +import { useMemo, useState } from "react" +import { Controller, useForm } from "react-hook-form" +import { MdOutlineFeedback } from "react-icons/md"; +import { LuBug } from "react-icons/lu" +import { ErrorText, Label } from "@/components/common/Form" +import { Loader } from "@/components/common/Loader" +import { HStack, Stack } from "@/components/layout/Stack" +import { DIALOG_CONTENT_CLASS } from "@/utils/layout/dialog" +import useCurrentRavenUser from "@/hooks/useCurrentRavenUser" + +type Props = { + open: boolean + onClose: VoidFunction +} +const CreateSupportTicketDialog = ({ open, onClose }: Props) => { + + return ( + + + Help and Support + Create a new support request + + + + ) +} + +interface SupportRequestFormFields { + requestType: "feedback" | "bug" + email: string + description: string +} +const SupportRequestForm = ({ onClose }: { onClose: () => void }) => { + + const { myProfile } = useCurrentRavenUser() + + const currentUserEmail = useMemo(() => { + const email = myProfile?.name; + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return email && emailRegex.test(email) ? email : ""; + }, [myProfile]); + + const { + control, + register, + formState: { errors }, + handleSubmit + } = useForm({ + defaultValues: { + requestType: "feedback", + email: currentUserEmail + } + }) + + const [loading, setLoading] = useState(false) + + const onSubmit = (data: SupportRequestFormFields) => { + setLoading(true) + + // Will send payload to API endpoint later on + + setTimeout(() => { + setLoading(false) + onClose() + }, 1500) + } + + return ( +
+ + ['feedback', 'bug'].includes(value) || 'Invalid request type' + }} + render={({ field: { onChange, value } }) => ( + + + + + + Feedback + + We'd love to hear your feedback! + + + + + + + Bug + + Encountered an issue? + + + + )} + /> + {errors.requestType && {errors.requestType.message}} + + + + + + + {errors.email && {errors.email?.message}} + + + + + +