mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: various bugs & issues
This commit is contained in:
parent
a95206bd74
commit
86e7ecc0fc
15 changed files with 128 additions and 94 deletions
|
|
@ -14,13 +14,13 @@ const CollectionAdminEditsArea = (props: any) => {
|
|||
|
||||
const deleteCollectionUI = async (collectionId: number) => {
|
||||
await deleteCollection(collectionId);
|
||||
revalidateTags(["collections"]);
|
||||
revalidateTags(["collections"], props.orgslug);
|
||||
// reload the page
|
||||
router.refresh();
|
||||
router.push(getUriWithOrg(props.orgslug, "/collections"));
|
||||
|
||||
// refresh page (FIX for Next.js BUG)
|
||||
window.location.reload();
|
||||
//window.location.reload();
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -43,13 +43,11 @@ function NewCollection(params: any) {
|
|||
org_id: org.org_id,
|
||||
};
|
||||
await createCollection(collection);
|
||||
revalidateTags(["collections"]);
|
||||
revalidateTags(["collections"], orgslug);
|
||||
router.prefetch(getUriWithOrg(orgslug, "/collections"));
|
||||
router.push(getUriWithOrg(orgslug, "/collections"));
|
||||
router.refresh();
|
||||
|
||||
// refresh page (FIX for Next.js BUG)
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import DocumentPdfActivity from "@components/Pages/Activities/DocumentPdf/Docume
|
|||
import ActivityIndicators from "@components/Pages/Courses/ActivityIndicators";
|
||||
import GeneralWrapperStyled from "@components/StyledElements/Wrappers/GeneralWrapper";
|
||||
import { useRouter } from "next/navigation";
|
||||
import AuthenticatedClientElement from "@components/Security/AuthenticatedClientElement";
|
||||
|
||||
interface ActivityClientProps {
|
||||
activityid: string;
|
||||
|
|
@ -64,8 +65,10 @@ function ActivityClient(props: ActivityClientProps) {
|
|||
<h1 className="font-bold text-gray-950 text-2xl first-letter:uppercase" >{activity.name}</h1>
|
||||
</div>
|
||||
<div className="flex space-x-2">
|
||||
<MarkStatus activityid={activityid} course={course} orgslug={orgslug} courseid={courseid} />
|
||||
<AuthenticatedClientElement checkMethod="authentication">
|
||||
<MarkStatus activityid={activityid} course={course} orgslug={orgslug} courseid={courseid} />
|
||||
|
||||
</AuthenticatedClientElement>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const CourseClient = (props: any) => {
|
|||
async function startCourseUI() {
|
||||
// Create activity
|
||||
await startCourse("course_" + courseid, orgslug);
|
||||
revalidateTags(['courses']);
|
||||
revalidateTags(['courses'], orgslug);
|
||||
router.refresh();
|
||||
|
||||
// refresh page (FIX for Next.js BUG)
|
||||
|
|
@ -33,7 +33,7 @@ const CourseClient = (props: any) => {
|
|||
// Close activity
|
||||
let activity = await removeCourse("course_" + courseid, orgslug);
|
||||
// Mutate course
|
||||
revalidateTags(['courses']);
|
||||
revalidateTags(['courses'], orgslug);
|
||||
router.refresh();
|
||||
|
||||
// refresh page (FIX for Next.js BUG)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ function Courses(props: CourseProps) {
|
|||
|
||||
async function deleteCourses(course_id: any) {
|
||||
await deleteCourseFromBackend(course_id);
|
||||
revalidateTags(['courses']);
|
||||
revalidateTags(['courses'], orgslug);
|
||||
|
||||
router.refresh();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import Toast from '@components/StyledElements/Toast/Toast';
|
|||
import { toast } from 'react-hot-toast';
|
||||
|
||||
const Login = () => {
|
||||
const [email, setEmail] = React.useState("admin@admin.admin");
|
||||
const [password, setPassword] = React.useState("admin");
|
||||
const [email, setEmail] = React.useState("");
|
||||
const [password, setPassword] = React.useState("");
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
|
|
@ -44,13 +44,13 @@ const Login = () => {
|
|||
return (
|
||||
<div>
|
||||
<LoginPage>
|
||||
<Toast></Toast>
|
||||
<Toast></Toast>
|
||||
<LoginBox>
|
||||
<FormLayout onSubmit={handleSubmit}>
|
||||
<FormField name="login-email">
|
||||
<Flex css={{ alignItems: 'baseline', justifyContent: 'space-between' }}>
|
||||
<FormLabel>Email</FormLabel>
|
||||
<FormMessage style={{color:"black"}} match="valueMissing">Please provide an email</FormMessage>
|
||||
<FormMessage style={{ color: "black" }} match="valueMissing">Please provide an email</FormMessage>
|
||||
</Flex>
|
||||
<Form.Control asChild>
|
||||
<Input onChange={handleEmailChange} type="text" />
|
||||
|
|
@ -59,7 +59,7 @@ const Login = () => {
|
|||
<FormField name="login-password">
|
||||
<Flex css={{ alignItems: 'baseline', justifyContent: 'space-between' }}>
|
||||
<FormLabel>Password</FormLabel>
|
||||
<FormMessage style={{color:"black"}} match="valueMissing">Please provide a password</FormMessage>
|
||||
<FormMessage style={{ color: "black" }} match="valueMissing">Please provide a password</FormMessage>
|
||||
</Flex>
|
||||
<Form.Control asChild>
|
||||
<Input type="password" onChange={handlePasswordChange} />
|
||||
|
|
|
|||
|
|
@ -6,38 +6,45 @@ import LearnHouseWhiteLogo from '@public/learnhouse_text_white.png';
|
|||
import AuthProvider, { AuthContext } from '@components/Security/AuthProvider';
|
||||
import Avvvatars from 'avvvatars-react';
|
||||
import Image from 'next/image';
|
||||
import AuthenticatedClientElement from '@components/Security/AuthenticatedClientElement';
|
||||
import { getOrganizationContextInfo } from '@services/organizations/orgs';
|
||||
|
||||
function SettingsLayout({ children, params }: { children: React.ReactNode, params: any }) {
|
||||
async function SettingsLayout({ children, params }: { children: React.ReactNode, params: any }) {
|
||||
const auth: any = React.useContext(AuthContext);
|
||||
const orgslug = params.orgslug;
|
||||
|
||||
let org = await getOrganizationContextInfo(orgslug, {});
|
||||
|
||||
return (
|
||||
<>
|
||||
<AuthProvider>
|
||||
<Main>
|
||||
<LeftWrapper>
|
||||
<LeftTopArea>
|
||||
|
||||
<Link href={"/"}><Image alt="Learnhouse logo" width={128} src={LearnHouseWhiteLogo}/></Link>
|
||||
{auth.isAuthenticated && (
|
||||
<Avvvatars value={auth.userInfo.user_object.user_id} style="shape" />
|
||||
)}
|
||||
</LeftTopArea>
|
||||
<LeftMenuWrapper>
|
||||
<MenuTitle>Account</MenuTitle>
|
||||
<ul>
|
||||
<li><Link href="/settings/account/profile">Profile</Link></li>
|
||||
<li><Link href="/settings/account/passwords">Passwords</Link></li>
|
||||
</ul>
|
||||
<MenuTitle>Organization</MenuTitle>
|
||||
<ul>
|
||||
<li><Link href="/settings/organization/general">General</Link></li>
|
||||
</ul>
|
||||
</LeftMenuWrapper>
|
||||
</LeftWrapper>
|
||||
<RightWrapper>
|
||||
{children}
|
||||
</RightWrapper>
|
||||
</Main></AuthProvider>
|
||||
<>
|
||||
<AuthProvider>
|
||||
<Main>
|
||||
<LeftWrapper>
|
||||
<LeftTopArea>
|
||||
|
||||
<Link href={"/"}><Image alt="Learnhouse logo" width={128} src={LearnHouseWhiteLogo} /></Link>
|
||||
{auth.isAuthenticated && (
|
||||
<Avvvatars value={auth.userInfo.user_object.user_id} style="shape" />
|
||||
)}
|
||||
</LeftTopArea>
|
||||
<LeftMenuWrapper>
|
||||
<MenuTitle>Account</MenuTitle>
|
||||
<ul>
|
||||
<li><Link href="/settings/account/profile">Profile</Link></li>
|
||||
<li><Link href="/settings/account/passwords">Passwords</Link></li>
|
||||
</ul>
|
||||
<AuthenticatedClientElement checkMethod='roles' orgId={org.org_id} >
|
||||
<MenuTitle>Organization</MenuTitle>
|
||||
<ul>
|
||||
<li><Link href="/settings/organization/general">General</Link></li>
|
||||
</ul>
|
||||
</AuthenticatedClientElement>
|
||||
</LeftMenuWrapper>
|
||||
</LeftWrapper>
|
||||
<RightWrapper>
|
||||
{children}
|
||||
</RightWrapper>
|
||||
</Main></AuthProvider>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
@ -59,7 +66,7 @@ const LeftWrapper = styled('div', {
|
|||
const LeftTopArea = styled('div', {
|
||||
display: 'flex',
|
||||
marginLeft: '20px',
|
||||
|
||||
|
||||
alignItems: 'center',
|
||||
|
||||
img: {
|
||||
|
|
@ -72,7 +79,7 @@ const LeftTopArea = styled('div', {
|
|||
placeContent: 'center',
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
|
||||
const LeftMenuWrapper = styled('div', {
|
||||
|
|
|
|||
|
|
@ -33,12 +33,9 @@ function OrganizationClient(props: any) {
|
|||
let org_id = org.org_id;
|
||||
await uploadOrganizationLogo(org_id, selectedFile);
|
||||
setSelectedFile(null); // Reset the selected file
|
||||
revalidateTags(['organizations']);
|
||||
revalidateTags(['organizations'], org.slug);
|
||||
router.refresh();
|
||||
|
||||
// refresh page (FIX for Next.js BUG)
|
||||
window.location.reload();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -55,6 +52,10 @@ function OrganizationClient(props: any) {
|
|||
const updateOrg = async (values: OrganizationValues) => {
|
||||
let org_id = org.org_id;
|
||||
await updateOrganization(org_id, values);
|
||||
|
||||
// Mutate the org
|
||||
revalidateTags(['organizations'], org.slug);
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function CreateCourseModal({ closeModal, orgslug }: any) {
|
|||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
let status = await createNewCourse(orgId, { name, description }, thumbnail);
|
||||
revalidateTags(['courses']);
|
||||
revalidateTags(['courses'], orgslug);
|
||||
setIsSubmitting(false);
|
||||
|
||||
if (status.org_id == orgId) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ function TrailCourseElement(props: TrailCourseElementProps) {
|
|||
// Close activity
|
||||
let activity = await removeCourse(course_id, props.orgslug);
|
||||
// Mutate course
|
||||
revalidateTags(['courses']);
|
||||
revalidateTags(['courses'], props.orgslug);
|
||||
|
||||
// Mutate
|
||||
mutate(`${getAPIUrl()}trail/org_slug/${props.orgslug}/trail`);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ interface AuthenticatedClientElementProps {
|
|||
|
||||
}
|
||||
|
||||
function AuthenticatedClientElement(props: AuthenticatedClientElementProps) {
|
||||
export const AuthenticatedClientElement = (props: AuthenticatedClientElementProps) => {
|
||||
const auth: any = React.useContext(AuthContext);
|
||||
|
||||
// Available roles
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context";
|
||||
import { denyAccessToUser } from "../react/middlewares/views";
|
||||
import { LEARNHOUSE_DOMAIN, LEARNHOUSE_HTTP_PROTOCOL } from "@services/config/config";
|
||||
import { getUriWithOrg, LEARNHOUSE_DOMAIN, LEARNHOUSE_HTTP_PROTOCOL } from "@services/config/config";
|
||||
|
||||
export const RequestBody = (method: string, data: any, next: any) => {
|
||||
let HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
|
@ -78,15 +78,16 @@ export const swrFetcher = async (url: string, body: any, router?: AppRouterInsta
|
|||
|
||||
export const errorHandling = (res: any) => {
|
||||
if (!res.ok) {
|
||||
const error: any = new Error(`${res.status}: ${res.statusText}`, {});
|
||||
const error: any = new Error(`${res.statusText}`);
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const revalidateTags = (tags: string[]) => {
|
||||
export const revalidateTags = (tags: string[], orgslug: string) => {
|
||||
const url = getUriWithOrg(orgslug, "");
|
||||
tags.forEach((tag) => {
|
||||
fetch(`${LEARNHOUSE_HTTP_PROTOCOL}${LEARNHOUSE_DOMAIN}/api/revalidate?tag=${tag}`);
|
||||
fetch(`${url}/api/revalidate?tag=${tag}`);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue