-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} |