Merge branch 'main' of http://git.wdipl.com/Siddhesh.More/SSA-Admin-Panel into tufail
This commit is contained in:
@@ -1,31 +1,19 @@
|
||||
import { Box, HStack, Text } from "@chakra-ui/react";
|
||||
import { Box, HStack, Skeleton, Text } from "@chakra-ui/react";
|
||||
import MainFrame from "../../../components/MainFrame"
|
||||
import { p } from "framer-motion/client";
|
||||
import AboutUsAddModel from "../../ManageCMS/AboutUs/AboutUsAddModel";
|
||||
import { useGetAboutUsQuery } from "../../../Redux/Service/manage.aboutus.service";
|
||||
|
||||
|
||||
interface AboutUsContent {
|
||||
id: number;
|
||||
content: string;
|
||||
}
|
||||
|
||||
interface ApiResponse {
|
||||
data: AboutUsContent[];
|
||||
}
|
||||
|
||||
|
||||
const AboutUs = () => {
|
||||
|
||||
// const {
|
||||
// data: data
|
||||
// } = useGetAboutUsQuery()
|
||||
const { data: response } = useGetAboutUsQuery<{ data: ApiResponse }>();
|
||||
const { data, isLoading } = useGetAboutUsQuery();
|
||||
|
||||
const content = data?.data?.[0]?.content
|
||||
console.log('====================================');
|
||||
console.log(response);
|
||||
// console.log(response);
|
||||
console.log('====================================');
|
||||
|
||||
const content = response?.data?.[0]?.content || "No content available";
|
||||
|
||||
return (
|
||||
|
||||
@@ -47,9 +35,35 @@ const AboutUs = () => {
|
||||
<AboutUsAddModel />
|
||||
</HStack>
|
||||
</HStack>
|
||||
<Text as={p} fontSize={"sm"} fontWeight={400} color={"#1D1D1D"} px={3} w={"85%"} mb={"15px"} >
|
||||
{/* Show Skeleton until content is available */}
|
||||
{isLoading || !content ? (
|
||||
<Box px={3} w="85%">
|
||||
<Skeleton height="20px" mb="10px" />
|
||||
<Skeleton height="20px" mb="10px" />
|
||||
<Skeleton height="20px" mb="10px" />
|
||||
<Skeleton height="20px" mb="10px" width="75%" />
|
||||
<Skeleton height="20px" mb="15px" width="90%" />
|
||||
<Skeleton height="20px" mb="10px" />
|
||||
<Skeleton height="20px" mb="10px" width="85%" />
|
||||
<Skeleton height="20px" mb="10px" />
|
||||
<Skeleton height="20px" width="70%" />
|
||||
</Box>
|
||||
) : (
|
||||
<Text
|
||||
as="p"
|
||||
fontSize="sm"
|
||||
fontWeight={400}
|
||||
color="#1D1D1D"
|
||||
px={3}
|
||||
w="85%"
|
||||
mb="15px"
|
||||
>
|
||||
{content}
|
||||
</Text>
|
||||
)}
|
||||
{/* <Text as={p} fontSize={"sm"} fontWeight={400} color={"#1D1D1D"} px={3} w={"85%"} mb={"15px"} >
|
||||
{content}
|
||||
</Text>
|
||||
</Text> */}
|
||||
{/* <Text as={p} fontSize={"sm"} fontWeight={400} color={"#1D1D1D"} px={3} w={"85%"} >
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam soluta doloremque quibusdam facilis quas, unde hic eaque doloribus sed perferendis atque, eos dolores eius consectetur iure sint adipisci itaque tempora fugit quidem culpa provident possimus. Ullam, vitae in voluptatum dignissimos, quos blanditiis sequi aut repellat error eaque veritatis unde quam temporibus adipisci consectetur neque vero exercitationem dolor cum numquam maiores alias, totam minima quas. Possimus, ratione harum. Alias laboriosam nesciunt esse fugit deserunt pariatur corporis tempora quia veniam laborum aliquid enim voluptatibus asperiores minima tempore repudiandae vero quo porro, doloribus explicabo sit beatae et hic natus. Non earum nisi reiciendis?
|
||||
</Text> */}
|
||||
|
||||
@@ -1,53 +1,189 @@
|
||||
import { FaRegEdit } from "react-icons/fa"
|
||||
import { DialogBody, DialogCloseTrigger, DialogContent, DialogFooter, DialogHeader, DialogRoot, DialogTitle, DialogTrigger } from "../../../components/ui/dialog"
|
||||
import { Field, Stack, Text, Textarea } from "@chakra-ui/react"
|
||||
import { Button } from "../../../components/ui/button"
|
||||
// import { FaRegEdit } from "react-icons/fa"
|
||||
// import { DialogBody, DialogCloseTrigger, DialogContent, DialogFooter, DialogHeader, DialogRoot, DialogTitle, DialogTrigger } from "../../../components/ui/dialog"
|
||||
// import { Field, Stack, Text, Textarea } from "@chakra-ui/react"
|
||||
// import { Button } from "../../../components/ui/button"
|
||||
// import { useUpdateAboutUsMutation } from "../../../Redux/Service/manage.aboutus.service"
|
||||
|
||||
// function AboutUsAddModel() {
|
||||
|
||||
// const [ updateAboutUs ] = useUpdateAboutUsMutation()
|
||||
|
||||
|
||||
// try {
|
||||
// const res = updateAboutUs({id:2, updatedData:''})
|
||||
// console.log(res);
|
||||
|
||||
|
||||
// } catch (error) {
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// return (
|
||||
|
||||
// <DialogRoot placement="center">
|
||||
// <DialogTrigger asChild>
|
||||
// {/* <Button bg={"transparent"} size="sm">
|
||||
// <MdOutlineRemoveRedEye style={{ cursor: "pointer", fontSize: "16px" }} />
|
||||
// </Button> */}
|
||||
// <Button bgColor={'#EEEEEE'} pl={3} pr={3} size={'xs'} color={'#000'}> <FaRegEdit color="#000" style={{ height: '14px', width: '14px' }} /> <Text color={"#000"} mt={1}>Edit</Text></Button>
|
||||
|
||||
// </DialogTrigger>
|
||||
|
||||
// <DialogContent
|
||||
// bg={"#fff"}
|
||||
// // w={{ lg: "60%", md: "230px" }}
|
||||
// w={{ base: '90%', md: '400px' }}
|
||||
// height={"auto"}
|
||||
|
||||
// p={3} // Reduced padding
|
||||
// bgSize={'md'}
|
||||
// >
|
||||
// <DialogHeader bg="white" >
|
||||
// <DialogTitle alignSelf="center" color="black" fontSize="14px">Edit</DialogTitle>
|
||||
// </DialogHeader>
|
||||
|
||||
// <DialogBody bg="white">
|
||||
// <Stack py={3} >
|
||||
|
||||
// <Field.Root>
|
||||
// <Field.Label color="black" pt={1} fontSize="12px">AboutUs</Field.Label>
|
||||
// <Textarea placeholder="" bgColor="#EEEEEE" color="black" border="none" pl={1} fontSize="12px" height="30px" pt={1.5} />
|
||||
// </Field.Root>
|
||||
// </Stack>
|
||||
// </DialogBody>
|
||||
// <DialogFooter display="flex" justifyContent="center" pt={"2"}>
|
||||
// <Button w="100%" bg="#02A0A0" color={"#fff"}>
|
||||
// Save
|
||||
// </Button>
|
||||
// </DialogFooter>
|
||||
|
||||
// <DialogCloseTrigger color="black" />
|
||||
// </DialogContent>
|
||||
// </DialogRoot >
|
||||
|
||||
// )
|
||||
// }
|
||||
|
||||
// export default AboutUsAddModel
|
||||
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { FaRegEdit } from "react-icons/fa";
|
||||
import {
|
||||
DialogBody,
|
||||
DialogCloseTrigger,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogRoot,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "../../../components/ui/dialog";
|
||||
import { Field, Stack, Text, Textarea } from "@chakra-ui/react";
|
||||
import { Button } from "../../../components/ui/button";
|
||||
import { useUpdateAboutUsMutation } from "../../../Redux/Service/manage.aboutus.service";
|
||||
|
||||
function AboutUsAddModel() {
|
||||
return (
|
||||
const [content, setContent] = useState(""); // State for the textarea input
|
||||
const [updateAboutUs, { isLoading }] = useUpdateAboutUsMutation(); // Mutation for updating About Us
|
||||
// const toast = useToast(); // Toast for feedback
|
||||
|
||||
// Handle form submission
|
||||
const handleSubmit = async (e: any) => {
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
try {
|
||||
// Call the updateAboutUs mutation
|
||||
const res = await updateAboutUs({ id: 2, updatedData: content }).unwrap();
|
||||
console.log(res);
|
||||
|
||||
// Show success toast
|
||||
// toast({
|
||||
// title: "Success",
|
||||
// description: "About Us content updated successfully",
|
||||
// status: "success",
|
||||
// duration: 5000,
|
||||
// isClosable: true,
|
||||
// });
|
||||
|
||||
// Clear the input field after successful submission
|
||||
setContent("");
|
||||
} catch (error) {
|
||||
// Show error toast
|
||||
// toast({
|
||||
// title: "Error",
|
||||
// description: "Failed to update About Us content",
|
||||
// status: "error",
|
||||
// duration: 5000,
|
||||
// isClosable: true,
|
||||
// });
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogRoot placement="center">
|
||||
<DialogTrigger asChild>
|
||||
{/* <Button bg={"transparent"} size="sm">
|
||||
<MdOutlineRemoveRedEye style={{ cursor: "pointer", fontSize: "16px" }} />
|
||||
</Button> */}
|
||||
<Button bgColor={'#EEEEEE'} pl={3} pr={3} size={'xs'} color={'#000'}> <FaRegEdit color="#000" style={{ height: '14px', width: '14px' }} /> <Text color={"#000"} mt={1}>Edit</Text></Button>
|
||||
|
||||
<Button bgColor="#EEEEEE" pl={3} pr={3} size="xs" color="#000">
|
||||
<FaRegEdit color="#000" style={{ height: "14px", width: "14px" }} />
|
||||
<Text color="#000" mt={1}>
|
||||
Edit
|
||||
</Text>
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
|
||||
<DialogContent
|
||||
bg={"#fff"}
|
||||
// w={{ lg: "60%", md: "230px" }}
|
||||
w={{ base: '90%', md: '400px' }}
|
||||
height={"auto"}
|
||||
|
||||
p={3} // Reduced padding
|
||||
bgSize={'md'}
|
||||
bg="#fff"
|
||||
w={{ base: "90%", md: "400px" }}
|
||||
height="auto"
|
||||
p={3}
|
||||
>
|
||||
<DialogHeader bg="white" >
|
||||
<DialogTitle alignSelf="center" color="black" fontSize="14px">Edit</DialogTitle>
|
||||
<DialogHeader bg="white">
|
||||
<DialogTitle alignSelf="center" color="black" fontSize="14px">
|
||||
Edit
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<DialogBody bg="white">
|
||||
<Stack py={3} >
|
||||
|
||||
<Stack py={3}>
|
||||
<Field.Root>
|
||||
<Field.Label color="black" pt={1} fontSize="12px">AboutUs</Field.Label>
|
||||
<Textarea placeholder="" bgColor="#EEEEEE" color="black" border="none" pl={1} fontSize="12px" height="30px" pt={1.5} />
|
||||
<Field.Label color="black" pt={1} fontSize="12px">
|
||||
AboutUs
|
||||
</Field.Label>
|
||||
<Textarea
|
||||
placeholder="Enter About Us content"
|
||||
bgColor="#EEEEEE"
|
||||
color="black"
|
||||
border="none"
|
||||
pl={1}
|
||||
fontSize="12px"
|
||||
height="100px" // Increased height for better usability
|
||||
pt={1.5}
|
||||
value={content} // Bind the state to the textarea
|
||||
onChange={(e) => setContent(e.target.value)} // Update state on change
|
||||
/>
|
||||
</Field.Root>
|
||||
</Stack>
|
||||
</DialogBody>
|
||||
<DialogFooter display="flex" justifyContent="center" pt={"2"}>
|
||||
<Button w="100%" bg="#02A0A0" color={"#fff"}>
|
||||
|
||||
<DialogFooter display="flex" justifyContent="center" pt="2">
|
||||
<Button
|
||||
w="100%"
|
||||
bg="#02A0A0"
|
||||
color="#fff"
|
||||
onClick={handleSubmit} // Trigger handleSubmit on button click
|
||||
// isLoading={isLoading} // Show loading state while the mutation is in progress
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
||||
<DialogCloseTrigger color="black" />
|
||||
</DialogContent>
|
||||
</DialogRoot >
|
||||
|
||||
)
|
||||
</DialogRoot>
|
||||
);
|
||||
}
|
||||
|
||||
export default AboutUsAddModel
|
||||
export default AboutUsAddModel;
|
||||
@@ -3,20 +3,10 @@ import MainFrame from "../../../components/MainFrame";
|
||||
import PrivacyPolicyAddModel from "./PrivacyPolicyAddModel";
|
||||
import { useGetPrivacyPolicyQuery } from "../../../Redux/Service/privacy.policy.service";
|
||||
|
||||
// Define interfaces
|
||||
interface PrivacyPolicyContent {
|
||||
id: number;
|
||||
content: string;
|
||||
}
|
||||
|
||||
interface ApiResponse {
|
||||
data: {data:PrivacyPolicyContent[]};
|
||||
isLoading: boolean
|
||||
}
|
||||
|
||||
const PrivacyPolicy = () => {
|
||||
// Fetch data using RTK Query with type annotations
|
||||
const { data, isLoading } = useGetPrivacyPolicyQuery<ApiResponse>();
|
||||
const { data, isLoading } = useGetPrivacyPolicyQuery();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export const aboutUs = createApi({
|
||||
|
||||
|
||||
// 🔹 GET: Fetch all posts
|
||||
getAboutUs: builder.query<AboutUs[], void>({
|
||||
getAboutUs: builder.query<AboutUsResponse, void>({
|
||||
query: () => "/about-us",
|
||||
}),
|
||||
|
||||
@@ -24,18 +24,18 @@ export const aboutUs = createApi({
|
||||
|
||||
// 🔹 POST: Create a new post
|
||||
createPost: builder.mutation<Post, Partial<Post>>({
|
||||
query: (newPost) => ({
|
||||
query: (data) => ({
|
||||
url: "/posts",
|
||||
method: "POST",
|
||||
body: newPost,
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
// 🔹 PUT: Update an existing post
|
||||
updatePost: builder.mutation<Post, { id: number; updatedData: Partial<Post> }>({
|
||||
updateAboutUs: builder.mutation<UpdateAboutUsResponse, UpdateAboutUsRequest>({
|
||||
query: ({ id, updatedData }) => ({
|
||||
url: `/posts/${id}`,
|
||||
method: "PUT",
|
||||
method: "POST",
|
||||
body: updatedData,
|
||||
}),
|
||||
}),
|
||||
@@ -52,9 +52,20 @@ export const aboutUs = createApi({
|
||||
|
||||
export const {
|
||||
useGetAboutUsQuery,
|
||||
useUpdateAboutUsMutation,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
useGetPostByIdQuery,
|
||||
useCreatePostMutation,
|
||||
useUpdatePostMutation,
|
||||
useCreatePostMutation,
|
||||
useDeletePostMutation
|
||||
} = aboutUs;
|
||||
|
||||
@@ -66,9 +77,27 @@ export type Post = {
|
||||
};
|
||||
|
||||
|
||||
export type UpdateAboutUsRequest={
|
||||
id: number; updatedData: string
|
||||
}
|
||||
|
||||
|
||||
export type UpdateAboutUsResponse={
|
||||
id: number; updatedData: string
|
||||
}
|
||||
|
||||
|
||||
export type AboutUs = {
|
||||
id: number;
|
||||
language_master_xid: number;
|
||||
content: string;
|
||||
is_active: boolean;
|
||||
};
|
||||
|
||||
// First define your interface
|
||||
interface AboutUsResponse {
|
||||
data: {
|
||||
content: string;
|
||||
// other fields...
|
||||
}[];
|
||||
}
|
||||
@@ -1,68 +1,16 @@
|
||||
import { createApi } from "@reduxjs/toolkit/query/react"; // Fix import
|
||||
import { baseQueryWithReauth } from "./apiSlice";
|
||||
|
||||
|
||||
|
||||
import { createApi } from "@reduxjs/toolkit/query/react";
|
||||
import { baseQueryWithReauth } from "./apiSlice"; // Ensure this is correctly configured
|
||||
import { PrivacyPolicyResponse } from "../../Types/privacyPolicyTypes";
|
||||
|
||||
export const privacyPolicy = createApi({
|
||||
reducerPath: "privacyPolicy",
|
||||
baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling
|
||||
baseQuery: baseQueryWithReauth, // Ensure this returns a valid `BaseQueryFn`
|
||||
endpoints: (builder) => ({
|
||||
// 🔹 GET: Fetch all privacy policies
|
||||
getPrivacyPolicy: builder.query<PrivacyPolicy[], void>({
|
||||
getPrivacyPolicy: builder.query<PrivacyPolicyResponse, void>({ // Fix types here
|
||||
query: () => "/privacy-policy",
|
||||
}),
|
||||
|
||||
// 🔹 GET: Fetch a single post by ID
|
||||
// getPostById: builder.query<Post, number>({
|
||||
// query: (id) => `/posts/${id}`,
|
||||
// }),
|
||||
|
||||
// 🔹 POST: Create a new post
|
||||
// createPost: builder.mutation<Post, Partial<Post>>({
|
||||
// query: (newPost) => ({
|
||||
// url: "/posts",
|
||||
// method: "POST",
|
||||
// body: newPost,
|
||||
// }),
|
||||
// }),
|
||||
|
||||
// 🔹 PUT: Update an existing post
|
||||
// updatePost: builder.mutation<Post, { id: number; updatedData: Partial<Post> }>({
|
||||
// query: ({ id, updatedData }) => ({
|
||||
// url: `/posts/${id}`,
|
||||
// method: "PUT",
|
||||
// body: updatedData,
|
||||
// }),
|
||||
// }),
|
||||
|
||||
// 🔹 DELETE: Remove a post by ID
|
||||
// deletePost: builder.mutation<{ success: boolean }, number>({
|
||||
// query: (id) => ({
|
||||
// url: `/posts/${id}`,
|
||||
// method: "DELETE",
|
||||
// }),
|
||||
// }),
|
||||
}),
|
||||
});
|
||||
|
||||
// Export hooks for usage in components
|
||||
export const {
|
||||
useGetPrivacyPolicyQuery, // Export the correct hook
|
||||
|
||||
} = privacyPolicy;
|
||||
|
||||
|
||||
// Define types at the top for better readability
|
||||
export type Post = {
|
||||
id: number;
|
||||
title: string;
|
||||
body: string;
|
||||
};
|
||||
|
||||
export type PrivacyPolicy = {
|
||||
id: number;
|
||||
language_master_xid: number;
|
||||
content: string;
|
||||
is_active: boolean;
|
||||
};
|
||||
// Export hook
|
||||
export const { useGetPrivacyPolicyQuery } = privacyPolicy;
|
||||
|
||||
13
src/Types/privacyPolicyTypes.tsx
Normal file
13
src/Types/privacyPolicyTypes.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface PrivacyPolicyContent {
|
||||
id: number;
|
||||
language_master_xid: number;
|
||||
content: string;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
export interface PrivacyPolicyResponse {
|
||||
status: "success" | "error"; // Assuming it can be "success" or "error"
|
||||
status_code: number;
|
||||
message: string;
|
||||
data: PrivacyPolicyContent[];
|
||||
}
|
||||
Reference in New Issue
Block a user