Skip to content

Commit 13bdeb4

Browse files
authored
Merge pull request #358 from summit-webapp/release/v1.2.2
Feat: ✨ New hook file added to publish blog data and utils func to handle data inside components.
2 parents 0726460 + 4a4b6c1 commit 13bdeb4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useEffect, useState } from 'react';
2+
import { useSelector } from 'react-redux';
3+
import getBlogDataAPI from '../../services/api/home-page-apis/blog-api';
4+
import { CONSTANTS } from '../../services/config/app-config';
5+
import { get_access_token } from '../../store/slices/auth/token-login-slice';
6+
import useHandleStateUpdate from '../GeneralHooks/handle-state-update-hook';
7+
const useHomeBlogData = () => {
8+
const [blogData, setBlogData] = useState<any>([]);
9+
const tokenFromStore: any = useSelector(get_access_token);
10+
const { isLoading, setIsLoading, errorMessage, setErrMessage }: any = useHandleStateUpdate();
11+
const { SUMMIT_APP_CONFIG }: any = CONSTANTS;
12+
const fetchBlogData = async () => {
13+
let getBlogData: any;
14+
setIsLoading(true);
15+
try {
16+
getBlogData = await getBlogDataAPI(SUMMIT_APP_CONFIG, tokenFromStore?.token);
17+
if (getBlogData?.status === 200 && getBlogData?.data?.message?.msg === 'success') {
18+
setBlogData(getBlogData?.data?.message?.data);
19+
} else {
20+
setErrMessage('No Data Found');
21+
}
22+
} catch (error) {
23+
setErrMessage('No Data Found');
24+
} finally {
25+
setIsLoading(false);
26+
}
27+
};
28+
29+
useEffect(() => {
30+
fetchBlogData();
31+
}, []);
32+
return { isLoading, blogData, errorMessage };
33+
};
34+
35+
export default useHomeBlogData;

utils/dataFormat.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const dateFormat = (dateString: any) => {
2+
const date = new Date(dateString);
3+
const day = date.getDate();
4+
const monthIndex = date.getMonth(); // 0-based index for months
5+
const year = date.getFullYear();
6+
// Array of month names
7+
const monthNames = [
8+
"January", "February", "March", "April", "May", "June",
9+
"July", "August", "September", "October", "November", "December"
10+
];
11+
// Get the full month name
12+
const monthName = monthNames[monthIndex];
13+
return `${monthName} ${day}, ${year}`;
14+
}

0 commit comments

Comments
 (0)