Skip to content

Commit

Permalink
Merge pull request #1515 from arjuncvinod/dev
Browse files Browse the repository at this point in the history
fix(wadhwani): fixed toast issue and loader added
  • Loading branch information
viraka authored May 19, 2024
2 parents 3107c9d + 7092765 commit 8687adb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/modules/Dashboard/modules/Wadhwani/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import {
} from "./services/api";
import toast from "react-hot-toast";
import styles from "./index.module.css";
import MuLoader from "@/MuLearnComponents/MuLoader/MuLoader";


const Wadhwani = () => {
const [data, setData] = useState<wadhwaniCourseResponse[]>([]);
const [clientToken, setClientToken] = useState("");
const [isLoading,setIsLoading]=useState(true)

useEffect(() => {
fetchData();
Expand All @@ -29,6 +32,7 @@ const Wadhwani = () => {
} else if (courses) {
setData(courses);
}
setIsLoading(false)
}
};

Expand All @@ -48,7 +52,8 @@ const Wadhwani = () => {
<div className={styles.wrapper}>
<h1>Wadhwani Foundation Courses</h1>
<div className={styles.container}>
{data.map(course => (
{isLoading?<MuLoader/>:
data.map(course => (
<div
key={course.courseId}
className={styles.card}
Expand Down
9 changes: 7 additions & 2 deletions src/modules/Dashboard/modules/Wadhwani/services/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { privateGateway } from "@/MuLearnServices/apiGateways";
import { dashboardRoutes } from "@/MuLearnServices/urls";
import { AxiosError } from "axios";

import toast from "react-hot-toast";
export const getWadhwaniClientToken = async () => {
try {
const response = await privateGateway.post(
Expand Down Expand Up @@ -47,6 +47,7 @@ export const getWadhwaniCourseLink = async (
clientToken: string,
courseId: string
) => {
const toastId=toast.loading("Fetching course link...")
try {
const response = await privateGateway.post(
dashboardRoutes.getWadhwaniCourseLink,
Expand All @@ -61,12 +62,16 @@ export const getWadhwaniCourseLink = async (
const message: wadhwaniCourseRedirectResponse = response?.data?.response;
if (message.data?.error?.code) {
return { response: null, error: message.data.error.description };
}else{
toast.success("Course link opened successfully!",{id:toastId})
}
return { response: message, error: null };
} catch (err: unknown) {
} catch (err: unknown) {
toast.error("Please try again later.",{id:toastId})
const error = err as AxiosError;
if (error?.response) {
throw error;

} else {
return { response: null, error: error.message };
}
Expand Down

0 comments on commit 8687adb

Please sign in to comment.