Skip to content

Commit

Permalink
Replaced old toast messages with the new
Browse files Browse the repository at this point in the history
  • Loading branch information
ravirajput10 committed Dec 26, 2024
1 parent e2d1711 commit 0f4ccd7
Show file tree
Hide file tree
Showing 67 changed files with 872 additions and 630 deletions.
3 changes: 3 additions & 0 deletions apps/web/app/dashboard4/(sidebar)/blog/[id]/page.tsx
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
10 changes: 9 additions & 1 deletion apps/web/app/dashboard4/(sidebar)/my-content/page.tsx
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,
ERROR_SNACKBAR_PREFIX,
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: ERROR_SNACKBAR_PREFIX,
description: e.message,
});
}
};

loadEnrolledCourses();
Expand Down
35 changes: 28 additions & 7 deletions apps/web/app/dashboard4/(sidebar)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import {
MediaSelector,
PageBuilderPropertyHeader,
Section,
useToast,
} from "@courselit/components-library";
import { FetchBuilder } from "@courselit/utils";
import {
APP_MESSAGE_CHANGES_SAVED,
BUTTON_SAVE,
ERROR_SNACKBAR_PREFIX,
MEDIA_SELECTOR_REMOVE_BTN_CAPTION,
MEDIA_SELECTOR_UPLOAD_BTN_CAPTION,
PROFILE_EMAIL_PREFERENCES,
Expand All @@ -41,6 +44,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 = useContext(ProfileContext);
const address = useContext(AddressContext);
Expand Down Expand Up @@ -83,7 +87,10 @@ export default function Page() {
setSubscribedToUpdates(response.user.subscribedToUpdates);
}
} catch (err: any) {
console.error(`Profile page: ${err.message}`);
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
}
};
if (profile.userId && address.backend) {
Expand Down Expand Up @@ -128,9 +135,15 @@ export default function Page() {

try {
await fetch.exec();
toast({
title: "",
description: APP_MESSAGE_CHANGES_SAVED,
});
} catch (err: any) {
console.error(err);
} finally {
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
}
};

Expand Down Expand Up @@ -175,9 +188,15 @@ export default function Page() {

try {
await fetch.exec();
toast({
title: "",
description: APP_MESSAGE_CHANGES_SAVED,
});
} catch (err: any) {
console.error(err);
} finally {
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
}
};

Expand Down Expand Up @@ -209,8 +228,10 @@ export default function Page() {
await fetch.exec();
} catch (err: any) {
setSubscribedToUpdates(!state);
console.error(err);
} finally {
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
}
};

Expand Down
45 changes: 39 additions & 6 deletions apps/web/app/dashboard4/(sidebar)/users/[id]/page.tsx
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 {
ERROR_SNACKBAR_PREFIX,
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,12 @@ export default function Page({ params }: { params: { id: string } }) {
if (response.tags) {
setTags(response.tags);
}
} catch (err) {}
} catch (err) {
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
}
}, [address.backend]);

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

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

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

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

if (!userData) {
Expand Down
13 changes: 12 additions & 1 deletion apps/web/app/dashboard4/(sidebar)/users/tags/new/page.tsx
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,
ERROR_SNACKBAR_PREFIX,
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,10 @@ export default function Page() {
router.replace("/dashboard4/users/tags");
}
} catch (err: any) {
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
} finally {
setLoading(false);
}
Expand Down
12 changes: 8 additions & 4 deletions apps/web/app/dashboard4/(sidebar)/users/users-hub.tsx
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 {
ERROR_SNACKBAR_PREFIX,
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,10 +133,11 @@ export default function UsersHub() {
setCount(response.count);
}
} catch (err) {
console.error(err);
} finally {
}
}, [address.backend, page, rowsPerPage, filters, filtersAggregator]);
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
}}, [address.backend, page, rowsPerPage, filters, filtersAggregator]);

useEffect(() => {
loadUsers();
Expand Down
11 changes: 9 additions & 2 deletions apps/web/app/dashboard4/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 { ERROR_SNACKBAR_PREFIX } from "@ui-config/strings";

export default function Layout({
address,
Expand All @@ -27,6 +28,7 @@ export default function Layout({
config: ServerConfig;
}) {
const [profile, setProfile] = useState(defaultState.profile);
const { toast } = useToast();

useEffect(() => {
const getUserProfile = async () => {
Expand Down Expand Up @@ -66,7 +68,12 @@ export default function Layout({
if (response.profile) {
setProfile(response.profile);
}
} catch (e) {}
} catch (err) {
toast({
title: ERROR_SNACKBAR_PREFIX,
description: err.message,
});
}
};

if (address) {
Expand Down
10 changes: 9 additions & 1 deletion apps/web/components/admin/blogs/blog-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { MoreVert } from "@courselit/icons";
import type { AppDispatch } from "@courselit/state-management";
import type { SiteInfo, Address } from "@courselit/common-models";
// import { connect } from "react-redux";
import { Chip, Menu2, MenuItem, Link } from "@courselit/components-library";
import {
Chip,
Menu2,
MenuItem,
Link,
useToast,
} from "@courselit/components-library";
import { deleteProduct } from "./helpers";
import { TableRow } from "@courselit/components-library";

Expand All @@ -34,6 +40,7 @@ export default function BlogItem({
prefix: string;
}) {
const product = details;
const { toast } = useToast();

return (
<TableRow key={product.courseId}>
Expand Down Expand Up @@ -76,6 +83,7 @@ export default function BlogItem({
onDeleteComplete: () => {
onDelete(position);
},
toast,
})
}
></MenuItem>
Expand Down
Loading

0 comments on commit 0f4ccd7

Please sign in to comment.