Skip to content

Commit

Permalink
Replaced old toast messages with the new (#531)
Browse files Browse the repository at this point in the history
* Replaced old toast messages with the new

* Distinction between success and error toasts

---------

Co-authored-by: Rajat Saxena <hi@rajatsaxena.dev>
  • Loading branch information
ravirajput10 and Rajat Saxena authored Feb 1, 2025
1 parent 4de57d6 commit e082faf
Show file tree
Hide file tree
Showing 118 changed files with 982 additions and 2,711 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MenuItem,
Skeleton,
Tabbs,
useToast,
} from "@courselit/components-library";
import { MoreVert } from "@courselit/icons";
import {
Expand Down Expand Up @@ -41,6 +42,7 @@ export default function Page({ params }: { params: { id: string } }) {
const { profile } = useContext(ProfileContext);
const course = useCourse(id, address);
const router = useRouter();
const { toast } = useToast();

return (
<DashboardContent breadcrumbs={breadcrumbs}>
Expand Down Expand Up @@ -83,6 +85,7 @@ export default function Page({ params }: { params: { id: string } }) {
`/dashboard4/blogs`,
);
},
toast,
})
}
></MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
Link,
Section,
Skeleton,
useToast,
} from "@courselit/components-library";
import { FetchBuilder } from "@courselit/utils";
import {
ACCOUNT_NO_PURCHASE_PLACEHOLDER,
ACCOUNT_PROGRESS_SUFFIX,
TOAST_TITLE_ERROR,
MY_CONTENT_HEADER,
VISIT_COURSE_BUTTON,
} from "@ui-config/strings";
Expand All @@ -22,6 +24,7 @@ const breadcrumbs = [{ label: MY_CONTENT_HEADER, href: "#" }];
export default function Page() {
const [courses, setCourses] = useState([]);
const [loaded, setLoaded] = useState(false);
const { toast } = useToast();

const { profile } = useContext(ProfileContext);
const address = useContext(AddressContext);
Expand Down Expand Up @@ -50,7 +53,12 @@ export default function Page() {
setCourses(response.courses);
}
setLoaded(true);
} catch (e: any) {}
} catch (e: any) {
toast({
title: TOAST_TITLE_ERROR,
description: e.message,
});
}
};

loadEnrolledCourses();
Expand Down
30 changes: 23 additions & 7 deletions apps/web/app/(with-contexts)/dashboard4/(sidebar)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {
MediaSelector,
PageBuilderPropertyHeader,
Section,
useToast,
} from "@courselit/components-library";
import { FetchBuilder } from "@courselit/utils";
import {
BUTTON_SAVE,
TOAST_TITLE_ERROR,
MEDIA_SELECTOR_REMOVE_BTN_CAPTION,
MEDIA_SELECTOR_UPLOAD_BTN_CAPTION,
PROFILE_EMAIL_PREFERENCES,
Expand All @@ -41,6 +43,7 @@ export default function Page() {
useState<Pick<Profile, "bio" | "name" | "avatar">>();
const [avatar, setAvatar] = useState<Partial<Media>>({});
const [subscribedToUpdates, setSubscribedToUpdates] = useState(false);
const { toast } = useToast();

const { profile, setProfile } = useContext(ProfileContext);
const address = useContext(AddressContext);
Expand Down Expand Up @@ -83,7 +86,11 @@ export default function Page() {
setSubscribedToUpdates(response.user.subscribedToUpdates);
}
} catch (err: any) {
console.error(`Profile page: ${err.message}`);
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};
if (profile.userId && address.backend) {
Expand Down Expand Up @@ -140,8 +147,11 @@ export default function Page() {
setProfile(response.user);
}
} catch (err: any) {
console.error(err);
} finally {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

Expand Down Expand Up @@ -198,8 +208,11 @@ export default function Page() {
setProfile(response.user);
}
} catch (err: any) {
console.error(err);
} finally {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

Expand Down Expand Up @@ -231,8 +244,11 @@ export default function Page() {
await fetch.exec();
} catch (err: any) {
setSubscribedToUpdates(!state);
console.error(err);
} finally {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import DashboardContent from "@components/admin/dashboard-content";
import { PermissionsEditor } from "@components/admin/users/permissions-editor";
import { AddressContext } from "@components/contexts";
import { UserWithAdminFields } from "@courselit/common-models";
import { ComboBox, Link, Section, Switch } from "@courselit/components-library";
import {
ComboBox,
Link,
Section,
Switch,
useToast,
} from "@courselit/components-library";
import { FetchBuilder } from "@courselit/utils";
import {
TOAST_TITLE_ERROR,
PAGE_HEADER_ALL_USER,
PAGE_HEADER_EDIT_USER,
SWITCH_ACCOUNT_ACTIVE,
Expand All @@ -28,6 +35,7 @@ export default function Page({ params }: { params: { id: string } }) {
const [tags, setTags] = useState([]);
const address = useContext(AddressContext);
const { id } = params;
const { toast } = useToast();

useEffect(() => {
getUserDetails();
Expand All @@ -49,7 +57,13 @@ export default function Page({ params }: { params: { id: string } }) {
if (response.tags) {
setTags(response.tags);
}
} catch (err) {}
} catch (err) {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
}, [address.backend]);

useEffect(() => {
Expand Down Expand Up @@ -86,7 +100,13 @@ export default function Page({ params }: { params: { id: string } }) {
if (response.user) {
setUserData(response.user);
}
} catch (err: any) {}
} catch (err: any) {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

// TODO: test this method. A hard-coded userId was there in the query.
Expand All @@ -107,7 +127,13 @@ export default function Page({ params }: { params: { id: string } }) {
try {
const response = await fetch.exec();
setEnrolledCourses(response.enrolledCourses);
} catch (err) {}
} catch (err) {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

const toggleActiveState = async (value: boolean) => {
Expand Down Expand Up @@ -137,7 +163,13 @@ export default function Page({ params }: { params: { id: string } }) {
if (response.user) {
setUserData(response.user);
}
} catch (err: any) {}
} catch (err: any) {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

const updateTags = async (tags: string[]) => {
Expand Down Expand Up @@ -173,7 +205,13 @@ export default function Page({ params }: { params: { id: string } }) {
if (response.user) {
setUserData(response.user);
}
} catch (err: any) {}
} catch (err: any) {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

if (!userData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
"use client";

import React, { useState, ChangeEvent, useContext } from "react";
import { Button, Form, FormField } from "@courselit/components-library";
import {
Button,
Form,
FormField,
useToast,
} from "@courselit/components-library";
import {
BTN_CONTINUE,
BTN_NEW_TAG,
BUTTON_CANCEL_TEXT,
TOAST_TITLE_ERROR,
USERS_MANAGER_PAGE_HEADING,
USERS_TAG_HEADER,
USERS_TAG_NEW_HEADER,
Expand Down Expand Up @@ -41,6 +47,7 @@ export default function Page() {
const [name, setName] = useState("");
const [loading, setLoading] = useState(false);
const router = useRouter();
const { toast } = useToast();
const { profile } = useContext(ProfileContext);

const createTag = async (e: FormEvent) => {
Expand Down Expand Up @@ -68,6 +75,11 @@ export default function Page() {
router.replace("/dashboard4/users/tags");
}
} catch (err: any) {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
} finally {
setLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import {
TableBody,
TableHead,
TableRow,
useToast,
} from "@courselit/components-library";
import { checkPermission, FetchBuilder } from "@courselit/utils";
import {
TOAST_TITLE_ERROR,
USER_TABLE_HEADER_JOINED,
USER_TABLE_HEADER_LAST_ACTIVE,
USER_TABLE_HEADER_NAME,
Expand All @@ -44,6 +46,7 @@ export default function UsersHub() {
const [filtersAggregator, setFiltersAggregator] =
useState<UserFilterAggregator>("or");
const [count, setCount] = useState(0);
const { toast } = useToast();

const { profile } = useContext(ProfileContext);

Expand Down Expand Up @@ -130,8 +133,11 @@ export default function UsersHub() {
setCount(response.count);
}
} catch (err) {
console.error(err);
} finally {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
}, [address.backend, page, rowsPerPage, filters, filtersAggregator]);

Expand Down
12 changes: 10 additions & 2 deletions apps/web/app/(with-contexts)/layout-with-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
TypefacesContext,
ServerConfigContext,
} from "@components/contexts";
import { Toaster } from "@courselit/components-library";
import { Toaster, useToast } from "@courselit/components-library";
import { TOAST_TITLE_ERROR } from "@ui-config/strings";
import { Session } from "next-auth";

export default function Layout({
Expand All @@ -30,6 +31,7 @@ export default function Layout({
session: Session | null;
}) {
const [profile, setProfile] = useState(defaultState.profile);
const { toast } = useToast();

useEffect(() => {
const getUserProfile = async () => {
Expand Down Expand Up @@ -69,7 +71,13 @@ export default function Layout({
if (response.profile) {
setProfile(response.profile);
}
} catch (e) {}
} catch (err) {
toast({
title: TOAST_TITLE_ERROR,
description: err.message,
variant: "destructive",
});
}
};

if (address && session) {
Expand Down
46 changes: 0 additions & 46 deletions apps/web/app/dashboard2/blog/[id]/blog-layout.tsx

This file was deleted.

Loading

0 comments on commit e082faf

Please sign in to comment.