diff --git a/src/Pages/Products/View/AddPage.tsx b/src/Pages/Products/View/AddPage.tsx
index dd0e534..8fa2c1b 100644
--- a/src/Pages/Products/View/AddPage.tsx
+++ b/src/Pages/Products/View/AddPage.tsx
@@ -44,7 +44,8 @@ const AddProductPage = () => {
acc[obj.Description] = obj.key;
return acc;
}, {});
- const jsonString = Object.keys(convertedArray).length === 0 ? null : JSON.stringify(convertedArray);
+ const jsonString = convertedArray && Object.keys(convertedArray).length === 0 ? null : JSON.stringify(convertedArray);
+
console.log(jsonString, "jsonString");
const FileimagesArray = values?.variable?.images?.filter((item: any) => typeof item !== 'string') || [];
diff --git a/src/Pages/Products/View/EditPage.tsx b/src/Pages/Products/View/EditPage.tsx
index 4444feb..bba9559 100644
--- a/src/Pages/Products/View/EditPage.tsx
+++ b/src/Pages/Products/View/EditPage.tsx
@@ -80,7 +80,7 @@ const ViewProduct = () => {
return acc;
}, {}) : {};
- const jsonString = Object.keys(convertedArray).length === 0 ? null : JSON.stringify(convertedArray);
+ const jsonString = convertedArray && Object.keys(convertedArray).length === 0 ? null : JSON.stringify(convertedArray);
const FileimagesArray = values?.variable?.images?.filter((item: any) => typeof item !== 'string') || [];
console.log(values?.variable?.images,"values?.variable?.images");
@@ -96,9 +96,8 @@ const ViewProduct = () => {
});
console.log(images,"images");
- console.clear()
- console.log(images,"images");
-
+
+
const Product = {
id:values?.product_id,
name: {
@@ -113,7 +112,7 @@ const ViewProduct = () => {
},
price: values?.price,
info: jsonString,
- images:images ?? "",
+ images:images,
main_photo:main_photo,
_method:"PUT"
}
diff --git a/src/Pages/SupportMessages/AttachmentButton.tsx b/src/Pages/SupportMessages/AttachmentButton.tsx
new file mode 100644
index 0000000..ae4288b
--- /dev/null
+++ b/src/Pages/SupportMessages/AttachmentButton.tsx
@@ -0,0 +1,33 @@
+import React, { useState, ChangeEvent } from 'react';
+import { TiAttachment } from "react-icons/ti";
+
+const FileUploadButton: React.FC = () => {
+ const [file, setFile] = useState
(null);
+ console.log(file);
+
+ const handleFileChange = (event: ChangeEvent) => {
+ if (event.target.files && event.target.files.length > 0) {
+ setFile(event.target.files[0]);
+ }
+ };
+ const handel_add_file = ()=>{
+ document.getElementById('fileInput')?.click()
+ }
+ return (
+
+
+
+
+
+
+
+ );
+};
+
+export default FileUploadButton;
+
\ No newline at end of file
diff --git a/src/Pages/SupportMessages/Chat.tsx b/src/Pages/SupportMessages/Chat.tsx
new file mode 100644
index 0000000..7894a65
--- /dev/null
+++ b/src/Pages/SupportMessages/Chat.tsx
@@ -0,0 +1,54 @@
+import React, { FormEvent } from 'react';
+import { useTranslation } from "react-i18next";
+import { SOCKET } from "../../enums/Socket";
+import useChatSocket from './useChatSocket';
+import { Message } from '../../types/socket';
+import AttachmentButton from './AttachmentButton';
+
+const Chat = () => {
+ const [t] = useTranslation();
+ const { messages, input, setInput, sendMessage, messagesEndRef } = useChatSocket();
+
+ const handleSubmit = (e: FormEvent) => {
+ e.preventDefault();
+ sendMessage(input);
+ setInput("");
+ };
+
+ return (
+
+
+ {messages?.length > 0 && (
+
+ {messages.map((msg: Message, index) => (
+
+ {msg.text}
+
+ ))}
+
+
+ )}
+
+
+
+ );
+};
+
+export default Chat;
diff --git a/src/Pages/SupportMessages/Page.tsx b/src/Pages/SupportMessages/Page.tsx
index e2639a0..d9f8b03 100644
--- a/src/Pages/SupportMessages/Page.tsx
+++ b/src/Pages/SupportMessages/Page.tsx
@@ -1,45 +1,44 @@
-
-import React from 'react'
-import DashBody from '../../Layout/Dashboard/DashBody'
-import DashHeader from '../../Layout/Dashboard/DashHeader'
-import LyTable from '../../Layout/Dashboard/LyTable'
-import useTableColumns from './useTableColumns'
-import { QueryStatusEnum } from '../../config/QueryStatus'
-import { useNavigate } from 'react-router-dom'
-import AddButton from '../../Layout/Dashboard/AddButton/AddButton'
-import { useGetSupportMessages } from '../../api/supportmessages'
-import SearchField from '../../Layout/Dashboard/SearchField'
+import React, { useState } from 'react';
+import { Data } from './fakeData';
+import Chat from './Chat';
+import AttachmentButton from './AttachmentButton';
function Page() {
+ const [selected_user, set_selected_user] = useState(null);
- const column =useTableColumns()
- const {data ,status } = useGetSupportMessages()
- const navigate = useNavigate()
- const totalRows = data?.meta?.total;
-
- return (
- // Pass Status to Layout
-
-
-
-
+ const handle_select_chat = (item: any) => {
+ set_selected_user(item?.id);
+ };
- {/*
navigate('/support_messages/add')}> */}
-
-
-
-
-
-
-
- )
+ return (
+
+
+
+
+
+
+ {Data?.map((item, index) => {
+ return (
+
handle_select_chat(item)}
+ className={item?.id === selected_user ? 'user_profile user_profile_active' : " user_profile "}
+ >
+

+
+
{item?.name}
+
{item?.lastMessage}
+
+
+ );
+ })}
+
+
+
+ {selected_user ?
:
Select chat to start messaging
}
+
+
+ );
}
-export default Page
-
+export default Page;
diff --git a/src/Pages/SupportMessages/View/AddForm.tsx b/src/Pages/SupportMessages/View/AddForm.tsx
deleted file mode 100644
index a1817d7..0000000
--- a/src/Pages/SupportMessages/View/AddForm.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-
-import React, { useEffect } from 'react'
-import { Col, Row } from 'reactstrap';
-import ValidationField from '../../../Components/ValidationField/ValidationField';
-import { useGetUsers } from '../../../api/users';
-import { useFormikContext } from 'formik';
-
-function Form() {
- const useFormatToSelect = (Data : any) => {
- const format = (data :any) => {
- if (!data) return [];
- return data.map((item :any) => ({
- value: item?.id,
- label: item?.name,
- }));
- };
-
- return format(Data);
- };
- const { data: user } = useGetUsers()
-
- const SelectData = useFormatToSelect(user?.data)
-
-
-
- return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- )
-}
-
-export default Form
-
-
diff --git a/src/Pages/SupportMessages/View/AddPage.tsx b/src/Pages/SupportMessages/View/AddPage.tsx
deleted file mode 100644
index cdb7258..0000000
--- a/src/Pages/SupportMessages/View/AddPage.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { getInitialValues, getValidationSchema, getDataToSend } from '../formUtil'
-import { Tab, TabList, TabPanel as TabBody, Tabs } from 'react-tabs'
-import 'react-tabs/style/react-tabs.css';
-import { MdLanguage } from 'react-icons/md'
-import ViewPage from '../../../Layout/Dashboard/ViewPage';
-import { useTranslation } from 'react-i18next';
-import useNavigateOnSuccess from '../../../Hooks/useNavigateOnSuccess';
-import { useAddSupportMessages } from '../../../api/supportmessages';
-import Form from './AddForm';
-
-const AddSupportMessagesPage = () => {
-
-
- const {mutate , isLoading:IsloadingButton , isSuccess} = useAddSupportMessages()
- const handleSubmit = (values:any)=>{
- console.log(values,"values");
-
- mutate(values)
-
-
- }
- const {t} = useTranslation();
-
- useNavigateOnSuccess(isSuccess , '/SupportMessages' )
-
-
-
- const ViewProps = { getInitialValues, getValidationSchema, getDataToSend, handleSubmit,IsloadingButton };
-
-
- return (
-
-
-
-
-
-
{t("BasicInfo")}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- )
-
-}
-
-export default AddSupportMessagesPage
\ No newline at end of file
diff --git a/src/Pages/SupportMessages/fakeData.ts b/src/Pages/SupportMessages/fakeData.ts
new file mode 100644
index 0000000..17a2fef
--- /dev/null
+++ b/src/Pages/SupportMessages/fakeData.ts
@@ -0,0 +1,67 @@
+export const Data = [
+ {
+ id: 1,
+ name: "Mohammed",
+ image: "/Logo.png",
+ lastMessage: "Hey, how are you?",
+ timestamp: "2024-06-10 12:34",
+ status: "online"
+ },
+ {
+ id: 2,
+ name: "Aisha",
+ image: "/Logo.png",
+ lastMessage: "Let's meet tomorrow. sadasdasd",
+ timestamp: "2024-06-10 11:30",
+ status: "offline"
+ },
+ {
+ id: 3,
+ name: "Ali",
+ image: "/Logo.png",
+ lastMessage: "Got it, thanks!",
+ timestamp: "2024-06-09 18:22",
+ status: "offline"
+ },
+ {
+ id: 3,
+ name: "Ali",
+ image: "/Logo.png",
+ lastMessage: "Got it, thanks!",
+ timestamp: "2024-06-09 18:22",
+ status: "offline"
+ },
+ {
+ id: 4,
+ name: "Ali",
+ image: "/Logo.png",
+ lastMessage: "Got it, thanks!",
+ timestamp: "2024-06-09 18:22",
+ status: "offline"
+ },
+ {
+ id: 5,
+ name: "Ali",
+ image: "/Logo.png",
+ lastMessage: "Got it, thanks!",
+ timestamp: "2024-06-09 18:22",
+ status: "offline"
+ },
+ {
+ id: 6,
+ name: "Ali",
+ image: "/Logo.png",
+ lastMessage: "Got it, thanks!",
+ timestamp: "2024-06-09 18:22",
+ status: "offline"
+ },
+ {
+ id: 7,
+ name: "Ali",
+ image: "/Logo.png",
+ lastMessage: "Got it, thanks!",
+ timestamp: "2024-06-09 18:22",
+ status: "offline"
+ },
+
+ ]
\ No newline at end of file
diff --git a/src/Pages/SupportMessages/formUtil.ts b/src/Pages/SupportMessages/formUtil.ts
deleted file mode 100644
index 8eb1c46..0000000
--- a/src/Pages/SupportMessages/formUtil.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-
-import * as Yup from "yup";
-import { buildFormData } from "../../api/helper/buildFormData";
-
-export const getInitialValues = (objectToEdit: any | null = null): any => {
- console.log(objectToEdit,"objectToEdit");
- return {
- whatsApp: "",
- subject: "",
- message: "",
- id:null,
- };
-};
-
-
-export const getValidationSchema = (editMode: boolean = false): Yup.Schema => {
- // Validate input
- return Yup.object().shape({
- whatsApp: Yup.string().required('Required'),
- subject: Yup.string().required('Required'),
- message: Yup.string().required('Required'),
- id: Yup.string().required('Required'),
-
- });
-};
-
-
-
-export const getDataToSend = (values: any): FormData => {
- const data = { ...values };
-
-
- const formData = new FormData();
- buildFormData(formData, data);
- return formData;
-};
-
-export const ChangeDataToPrint = (data:any)=>{
-
- let new_array = data
- for(let i =0 ; i {
+ const [messages, setMessages] = useState([]);
+ const [input, setInput] = useState("");
+ const messagesEndRef = useRef(null);
+ const Socket = getSocket();
+
+ const scrollToBottom = () => {
+ if (messagesEndRef.current) {
+ messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
+ }
+ };
+
+ useEffect(() => {
+ Socket.on(SOCKET.EVENT_SEND_MESSAGE, (msg: string) => {
+ setMessages((prevMessages) => [
+ ...prevMessages,
+ { type: SOCKET.INCOMING, text: msg },
+ ]);
+ });
+
+ return () => {
+ disconnectSocket();
+ };
+ }, []);
+
+ useEffect(() => {
+ scrollToBottom();
+ }, [messages]);
+
+ const sendMessage = (msg: string) => {
+ if (msg.trim()) {
+
+ Socket.emit(SOCKET.EVENT_SEND_MESSAGE, msg);
+ setMessages((prevMessages) => [
+ ...prevMessages,
+ { type: SOCKET.OUTGOING, text: msg },
+ ]);
+ }
+ };
+
+ return { messages, input, setInput, sendMessage, messagesEndRef };
+};
+
+export default useChatSocket;
diff --git a/src/Pages/SupportMessages/useTableColumns.tsx b/src/Pages/SupportMessages/useTableColumns.tsx
deleted file mode 100644
index 23e955d..0000000
--- a/src/Pages/SupportMessages/useTableColumns.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-
-import React, { useMemo } from "react";
-import { useTranslation } from "react-i18next";
-import Actions from "../../Components/Ui/tables/Actions";
-import ColumnsImage from "../../Components/Columns/ColumnsImage";
-import { useNavigate } from "react-router-dom";
-import { useDeleteSupportMessages } from "../../api/supportmessages";
-
-
-const useTableColumns :any = () => {
- const [t] = useTranslation();
- const deleteMutation = useDeleteSupportMessages()
- const navigate = useNavigate()
-
- return useMemo(
- () => [
-
- {
- name: t("email"),
- center: true,
- selector: (row: any) => row.email, // Specify selector function for sorting
- },
-
- {
- name: t("whatsApp"),
- center: true,
- selector: (row: any) => row.whatsApp, // Specify selector function for sorting
- },
-
- {
- name: t("subject"),
- center: true,
- selector: (row: any) => row.subject, // Specify selector function for sorting
- },
- {
- name: t("message"),
- center: true,
- selector: (row: any) => row.message, // Specify selector function for sorting
- },
- {
- name: "#",
- sortable: false,
- center: true,
- cell: (row:any) => (
- navigate(`/support_messages/${row.id}`) }
- showView={false}
- showEdit={false}
- onDelete={() => deleteMutation.mutate({ id: row.id })}
- />
- ),
- },
-
- ],
- [t]
- );
-};
-
-export default useTableColumns;
-
diff --git a/src/Routes.tsx b/src/Routes.tsx
index cbfbbb7..1ee7442 100644
--- a/src/Routes.tsx
+++ b/src/Routes.tsx
@@ -32,7 +32,6 @@ import EditSlider from "./Pages/Slider/View/EditPage";
import SupportMessagesPage from "./Pages/SupportMessages/Page";
-import AddSupportMessagesPage from "./Pages/SupportMessages/View/AddPage";
// import EditSupportMessages from "./Pages/SupportMessages/View/EditPage";
import UsersPage from "./Pages/Users/Page";
@@ -184,21 +183,17 @@ export const RoutesLinks: RoutesLinksType[] = [
element: ,
hidden:true
},
- {
- name: "SupportMessages",
- element: ,
- icon: ,
- href: "/support_messages",
- },
+ // {
+ // name: "SupportMessages",
+ // element: ,
+ // icon: ,
+ // href: "/support_messages",
+ // },
// {
// href: "/support_messages/:id",
// element: ,
// hidden:true
// },
- {
- href: "/support_messages/add",
- element: ,
- hidden:true
- },
+
]
\ No newline at end of file
diff --git a/src/Styles/AppStyle/Import.scss b/src/Styles/AppStyle/Import.scss
index 36643f3..a568b8d 100644
--- a/src/Styles/AppStyle/Import.scss
+++ b/src/Styles/AppStyle/Import.scss
@@ -17,6 +17,6 @@
@import '../Layout/FillterSection.scss';
-
+@import '../page/SupportMessage.scss'
diff --git a/src/Styles/AppStyle/Mixing.scss b/src/Styles/AppStyle/Mixing.scss
index 5641f40..0949e4c 100644
--- a/src/Styles/AppStyle/Mixing.scss
+++ b/src/Styles/AppStyle/Mixing.scss
@@ -18,4 +18,24 @@
@mixin GlassModeCover{
background-color: rgba(16 18 27 / 40%);
backdrop-filter: blur(24px);
+}
+@mixin Scrollbar() {
+ scroll-behavior: smooth;
+ scroll-padding: 10rem;
+ &::-webkit-scrollbar {
+ width: 0.4vw;
+ max-height: 10px;
+ }
+
+ /* Handle */
+ &::-webkit-scrollbar-thumb {
+ background-color: var(--secondary);
+ border-radius: 5px; /* Adjust border-radius as needed */
+ }
+
+ /* Track */
+ &::-webkit-scrollbar-track {
+ border-radius: 5px; /* Adjust border-radius as needed */
+ background-color: #d3d5d7; /* Set to desired background color */
+ }
}
\ No newline at end of file
diff --git a/src/Styles/AppStyle/Varibils.scss b/src/Styles/AppStyle/Varibils.scss
index a9aaec8..0236e4b 100644
--- a/src/Styles/AppStyle/Varibils.scss
+++ b/src/Styles/AppStyle/Varibils.scss
@@ -1,11 +1,11 @@
:root {
- --primary:red ;
+ --primary:#eb671b ;
--secondary : #565656;
--text: #565656;
--bg: #ffffff;
--bg2: #f8f8f8;
--shadow: rgba(0, 0, 0, 0.15);
- --gray : rgb(207, 210, 214);
+ --gray : #e6e5eb54;
--linear : linear-gradient(118deg, #2D9CDB, #2D9CDB)
}
diff --git a/src/Styles/Layout/SideBar.scss b/src/Styles/Layout/SideBar.scss
index 15fd911..aed58d5 100644
--- a/src/Styles/Layout/SideBar.scss
+++ b/src/Styles/Layout/SideBar.scss
@@ -36,13 +36,17 @@ overflow-x: hidden;
}
.SideBar_Top {
- @include Flex;
+ display: flex;
+ align-items: center;
+ justify-content: center;
margin-block: 20px;
+ width: 100%;
color: var(--primary);
z-index: 9999999;
img{
margin-inline: 10px;
- width: 60px;
+ width: 40px;
+ border-radius: 20px;
}
.HamburgerMenu{
z-index: 999999999999999;
diff --git a/src/Styles/page/SupportMessage.scss b/src/Styles/page/SupportMessage.scss
new file mode 100644
index 0000000..d875f0b
--- /dev/null
+++ b/src/Styles/page/SupportMessage.scss
@@ -0,0 +1,156 @@
+.support_message{
+ background-color: var(--bg);
+ @include Shadow;
+ display: flex;
+
+ gap: 5%;
+ padding: 2% 2% 8% 2%;
+ border-radius: 2%;
+ .support_message_left{
+ min-width: 250px;
+ display: flex;
+ flex-direction: column;
+ gap: 20px;
+ max-height: 60vh;
+ overflow-y: scroll ;
+ @include Scrollbar;
+ >span{
+ >input{
+ all: unset;
+ max-width: 180px;
+ height: 40px;
+ padding-inline: 20px;
+ border-radius: 29px;
+ color: black;
+ background:var(--gray);
+
+ }
+ }
+ .user_profiles{
+ display: flex;
+ flex-direction: column;
+ // padding-inline: 20px;
+ // border-right: 1px solid gray;
+.user_profile_active{
+ background: var(--gray);
+
+}
+ .user_profile{
+ display: flex;
+ gap: 20px;
+ padding: 10px 20px;
+ cursor: pointer;
+ &:hover{
+ background: var(--gray);
+ }
+
+ >img{
+ border-radius: 50%;
+ width: 40px;
+ height: 40px;
+ }
+
+ >div{
+ display: flex;
+ flex-direction: column;
+ width: 75%;
+ h1{
+ font-size: 20px;
+ margin-bottom: 0;
+
+
+ }
+ p{
+ font-size: 14px;
+ margin-bottom: 0;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ }
+ }
+ }
+ }
+ }
+ .support_message_right{
+ width: 100%;
+ // align-self: flex-end;
+
+ &:has(input){
+ align-self: flex-end;
+ }
+ div{
+ width: 100%;
+ height: 100%;
+ }
+
+ }
+ .messages {
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+ overflow-y: auto;
+ &::-webkit-scrollbar {
+ display: none;
+ }
+ }
+
+ main {
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+ padding: 20px 20px;
+ max-height: 60vh;
+
+ .incoming {
+ background-color: var(--gray);
+ color: var(--text);
+ padding: 15px;
+ border-top-left-radius: 10px;
+ border-top-right-radius: 10px;
+ border-bottom-right-radius: 10px;
+ font-size: 13px;
+ width: fit-content;
+ }
+ .outgoing {
+ direction: rtl;
+ align-self: flex-end;
+ background-color: var(--gray);
+ color: var(--text);
+ padding: 15px;
+ border-top-left-radius: 10px;
+ border-top-right-radius: 10px;
+ border-bottom-left-radius: 10px;
+ font-size: 13px;
+ width: fit-content;
+
+ }
+ .socket_input {
+ background: var(--gray);
+ outline: none;
+ border: none;
+ border-radius: 4px;
+ padding: 6px 10px;
+ width: 100%;
+ height: 40px;
+
+ color: var(--text);
+ &::placeholder {
+ color: #9f9f9f;
+ }
+ }
+ }
+}
+
+.select_message{
+ display: flex;
+ justify-content: start;
+ align-items: center;
+ >h1{
+ width: 50%;
+ }
+}
+
+.socket_form{
+ display: flex;
+
+}
\ No newline at end of file
diff --git a/src/api/config.ts b/src/api/config.ts
index 568e610..66caf15 100644
--- a/src/api/config.ts
+++ b/src/api/config.ts
@@ -5,15 +5,20 @@ export const BaseURL = `https://back-demo.dmmobiles.com/api/`;
export const ImageBaseURL = `https://back-demo.dmmobiles.com`;
-// export const BaseURL = `http://192.168.1.112:8000/api/`;
-// export const ImageBaseURL = `http://192.168.1.112:8000`;
+// export const BaseURL = `http://192.168.1.122:8000/api/`;
+// export const ImageBaseURL = `http://192.168.1.122:8000`;
export const BaseURL_IMAGE = BaseURL.slice(0,-1);
-const PROJECT_NAME = "Hijab"
+
+
+
+const PROJECT_NAME = "DM_DAHBOARD"
export const TOKEN_KEY = PROJECT_NAME + "_TOKEN"
+export const TOKEN_KEY_SOCKET = PROJECT_NAME + "_SOKCET_TOKEN"
+
+
export const USER_KEY = PROJECT_NAME + "_USER"
-
diff --git a/src/config/AppKey.ts b/src/config/AppKey.ts
deleted file mode 100644
index 5b81dac..0000000
--- a/src/config/AppKey.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-const PROJECT_NAME = "Hijab_DAHBOARD"
-
-export const TOKEN_KEY = PROJECT_NAME + "_TOKEN"
-export const TOKEN_KEY_SOCKET = PROJECT_NAME + "_SOKCET_TOKEN"
-
-export const USER_KEY = PROJECT_NAME + "_USER"
-
-
-/// 1825|laravel_sanctum_RpRqXDf1jg1Jgb0VjnJcUzPpSmX46PD7h8jB8ag372d0778a
diff --git a/src/enums/Socket.ts b/src/enums/Socket.ts
new file mode 100644
index 0000000..c5a0d13
--- /dev/null
+++ b/src/enums/Socket.ts
@@ -0,0 +1,6 @@
+export enum SOCKET {
+ EVENT_SEND_MESSAGE = "chat_message",
+ INCOMING = "incoming",
+ OUTGOING = "outgoing",
+ }
+
\ No newline at end of file
diff --git a/src/lib/SocketProvider.tsx b/src/lib/SocketProvider.tsx
index aa00e9d..e5d6b80 100644
--- a/src/lib/SocketProvider.tsx
+++ b/src/lib/SocketProvider.tsx
@@ -1,37 +1,28 @@
+const BASE_URL = "ws://localhost:9000";
-import { Socket, io } from 'socket.io-client';
-import { TOKEN_KEY_SOCKET } from '../config/AppKey';
-
-
-export const BASE_URL_SOCKET = 'http://192.168.1.14:8001/';
-var socket :Socket | null = null ;
-
-
-function InitSocket(){
+import { io, Socket } from "socket.io-client";
+import { TOKEN_KEY } from "../api/config";
+var socket: null | Socket = null;
+export const getSocket = () => {
+ const token = localStorage.getItem(TOKEN_KEY)
+ if (!socket) {
+
+ socket = io(BASE_URL, {
+ autoConnect: true,
+ transports: ["websocket"],
+ auth:{
+ token: token,
+ }
+ });
+ }
+ return socket;
+};
- if (!socket){
- socket = io(BASE_URL_SOCKET , {
- transports:['websocket'],
- autoConnect:true,
- query:{
- token:localStorage.getItem(TOKEN_KEY_SOCKET),
-
- }
- });
- }
-}
-
-export const disconnectSocket = ()=>{
-
- socket?.disconnect();
+export const disconnectSocket = () => {
+ if (socket) {
+ socket.disconnect();
socket = null;
-}
-export const getScoket = ()=>{
-
- InitSocket();
- return socket;
-}
-
-
+ }
+};
diff --git a/src/lib/state mangment/AuthState.ts b/src/lib/state mangment/AuthState.ts
index b2bd147..bdd8d33 100644
--- a/src/lib/state mangment/AuthState.ts
+++ b/src/lib/state mangment/AuthState.ts
@@ -1,5 +1,5 @@
import {create} from 'zustand';
-import { TOKEN_KEY, TOKEN_KEY_SOCKET, USER_KEY } from '../../config/AppKey';
+import { TOKEN_KEY, TOKEN_KEY_SOCKET, USER_KEY } from '../../api/config';
interface LoginResponse {
token:string ,
@@ -20,6 +20,8 @@ const useAuthState = create((set) => {
const storedUser :any = localStorage.getItem(USER_KEY) ;
const storedToken = localStorage.getItem(TOKEN_KEY);
+ console.log(storedToken);
+
const initialUser = (storedUser && storedUser !== 'undefined') ? JSON.parse(storedUser) : null;
return {
diff --git a/src/types/socket.ts b/src/types/socket.ts
new file mode 100644
index 0000000..43db076
--- /dev/null
+++ b/src/types/socket.ts
@@ -0,0 +1,4 @@
+export interface Message {
+ type: "incoming" | "outgoing";
+ text: string;
+}
diff --git a/vite.config.js b/vite.config.js
new file mode 100644
index 0000000..4e690eb
--- /dev/null
+++ b/vite.config.js
@@ -0,0 +1,11 @@
+import { defineConfig } from 'vite';
+import react from '@vitejs/plugin-react';
+
+export default defineConfig(() => {
+ return {
+ build: {
+ outDir: 'build',
+ },
+ plugins: [react()],
+ };
+});
\ No newline at end of file