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

Feat: ✨ New hook file added to publish blog data and utils func to handle data inside components. #358

Merged
merged 1 commit into from
Jan 27, 2025
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
35 changes: 35 additions & 0 deletions hooks/HomePageHooks/useHomeBlogData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import getBlogDataAPI from '../../services/api/home-page-apis/blog-api';
import { CONSTANTS } from '../../services/config/app-config';
import { get_access_token } from '../../store/slices/auth/token-login-slice';
import useHandleStateUpdate from '../GeneralHooks/handle-state-update-hook';
const useHomeBlogData = () => {
const [blogData, setBlogData] = useState<any>([]);
const tokenFromStore: any = useSelector(get_access_token);
const { isLoading, setIsLoading, errorMessage, setErrMessage }: any = useHandleStateUpdate();
const { SUMMIT_APP_CONFIG }: any = CONSTANTS;
const fetchBlogData = async () => {
let getBlogData: any;
setIsLoading(true);
try {
getBlogData = await getBlogDataAPI(SUMMIT_APP_CONFIG, tokenFromStore?.token);
if (getBlogData?.status === 200 && getBlogData?.data?.message?.msg === 'success') {
setBlogData(getBlogData?.data?.message?.data);
} else {
setErrMessage('No Data Found');
}
} catch (error) {
setErrMessage('No Data Found');
} finally {
setIsLoading(false);
}
};

useEffect(() => {
fetchBlogData();
}, []);
return { isLoading, blogData, errorMessage };
};

export default useHomeBlogData;
14 changes: 14 additions & 0 deletions utils/dataFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const dateFormat = (dateString: any) => {
const date = new Date(dateString);
const day = date.getDate();
const monthIndex = date.getMonth(); // 0-based index for months
const year = date.getFullYear();
// Array of month names
const monthNames = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
// Get the full month name
const monthName = monthNames[monthIndex];
return `${monthName} ${day}, ${year}`;
}