Skip to content

Commit

Permalink
Merge pull request #358 from summit-webapp/release/v1.2.2
Browse files Browse the repository at this point in the history
Feat: ✨ New hook file added to publish blog data and utils func to handle data inside components.
  • Loading branch information
karan1633 authored Jan 27, 2025
2 parents 0726460 + 4a4b6c1 commit 13bdeb4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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}`;
}

0 comments on commit 13bdeb4

Please sign in to comment.