-
-
-
-
-
-
-
Error
-
Something went wrong
-
-
-
+ return (
+
+
+
+
+
+
+
+
Error
+
Something went wrong
+
- )
+
+
+ )
}
-export default ErrorUI
\ No newline at end of file
+export default ErrorUI
diff --git a/apps/web/components/StyledElements/Form/Form.tsx b/apps/web/components/StyledElements/Form/Form.tsx
index cc877cbc..273a48da 100644
--- a/apps/web/components/StyledElements/Form/Form.tsx
+++ b/apps/web/components/StyledElements/Form/Form.tsx
@@ -1,104 +1,110 @@
-import React from 'react';
-import * as Form from '@radix-ui/react-form';
-import { styled } from '@stitches/react';
-import { blackA } from '@radix-ui/colors';
-import { Info } from 'lucide-react';
+import React from 'react'
+import * as Form from '@radix-ui/react-form'
+import { styled } from '@stitches/react'
+import { blackA } from '@radix-ui/colors'
+import { Info } from 'lucide-react'
const FormLayout = (props: any, onSubmit: any) => (
-
- {props.children}
-
-);
+
+ {props.children}
+
+)
-export const FormLabelAndMessage = (props: { label: string, message?: string }) => (
-
-
{props.label}
- {props.message &&
|| <>>}
-
-);
+export const FormLabelAndMessage = (props: {
+ label: string
+ message?: string
+}) => (
+
+
{props.label}
+ {(props.message && (
+
+ )) || <>>}
+
+)
export const FormRoot = styled(Form.Root, {
- margin: 7
-});
+ margin: 7,
+})
export const FormField = styled(Form.Field, {
- display: 'grid',
- marginBottom: 10,
-});
+ display: 'grid',
+ marginBottom: 10,
+})
export const FormLabel = styled(Form.Label, {
- fontSize: 15,
- fontWeight: 500,
- lineHeight: '35px',
- color: 'black',
-});
+ fontSize: 15,
+ fontWeight: 500,
+ lineHeight: '35px',
+ color: 'black',
+})
export const FormMessage = styled(Form.Message, {
- fontSize: 13,
- color: 'white',
- opacity: 0.8,
-});
+ fontSize: 13,
+ color: 'white',
+ opacity: 0.8,
+})
-export const Flex = styled('div', { display: 'flex' });
+export const Flex = styled('div', { display: 'flex' })
export const inputStyles = {
- all: 'unset',
- boxSizing: 'border-box',
- width: '100%',
- display: 'inline-flex',
- alignItems: 'center',
- justifyContent: 'center',
- borderRadius: 4,
- fontSize: 15,
- color: '#7c7c7c',
- background: "#F9FAFB",
- boxShadow: `0 0 0 1px #edeeef`,
- '&:hover': { boxShadow: `0 0 0 1px #edeeef` },
- '&:focus': { boxShadow: `0 0 0 2px #edeeef` },
- '&::selection': { backgroundColor: blackA.blackA9, color: 'white' },
-
-};
+ all: 'unset',
+ boxSizing: 'border-box',
+ width: '100%',
+ display: 'inline-flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ borderRadius: 4,
+ fontSize: 15,
+ color: '#7c7c7c',
+ background: '#F9FAFB',
+ boxShadow: `0 0 0 1px #edeeef`,
+ '&:hover': { boxShadow: `0 0 0 1px #edeeef` },
+ '&:focus': { boxShadow: `0 0 0 2px #edeeef` },
+ '&::selection': { backgroundColor: blackA.blackA9, color: 'white' },
+}
export const Input = styled('input', {
- ...inputStyles,
- height: 35,
- lineHeight: 1,
- padding: '0 10px',
- border: 'none',
-});
+ ...inputStyles,
+ height: 35,
+ lineHeight: 1,
+ padding: '0 10px',
+ border: 'none',
+})
export const Textarea = styled('textarea', {
- ...inputStyles,
- resize: 'none',
- padding: 10,
-});
+ ...inputStyles,
+ resize: 'none',
+ padding: 10,
+})
export const ButtonBlack = styled('button', {
- variants: {
- state: {
- "loading": {
- pointerEvents: 'none',
- backgroundColor: "#808080",
- },
- "none": {
- },
- },
+ variants: {
+ state: {
+ loading: {
+ pointerEvents: 'none',
+ backgroundColor: '#808080',
+ },
+ none: {},
},
- all: 'unset',
- display: 'inline-flex',
- alignItems: 'center',
- justifyContent: 'center',
- borderRadius: 8,
- padding: '0 15px',
- fontSize: 15,
- lineHeight: 1,
- fontWeight: 500,
- height: 35,
+ },
+ all: 'unset',
+ display: 'inline-flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ borderRadius: 8,
+ padding: '0 15px',
+ fontSize: 15,
+ lineHeight: 1,
+ fontWeight: 500,
+ height: 35,
- background: "#000000",
- color: "#FFFFFF",
- '&:hover': { backgroundColor: "#181818", cursor: "pointer" },
- '&:focus': { boxShadow: `0 0 0 2px black` },
-});
+ background: '#000000',
+ color: '#FFFFFF',
+ '&:hover': { backgroundColor: '#181818', cursor: 'pointer' },
+ '&:focus': { boxShadow: `0 0 0 2px black` },
+})
-export default FormLayout;
\ No newline at end of file
+export default FormLayout
diff --git a/apps/web/components/StyledElements/Modal/Modal.tsx b/apps/web/components/StyledElements/Modal/Modal.tsx
index 6c5584d7..fcbda31f 100644
--- a/apps/web/components/StyledElements/Modal/Modal.tsx
+++ b/apps/web/components/StyledElements/Modal/Modal.tsx
@@ -1,158 +1,155 @@
-'use client';
-import React from 'react';
-import * as Dialog from '@radix-ui/react-dialog';
-import { styled, keyframes } from '@stitches/react';
-import { blackA, mauve } from '@radix-ui/colors';
-import { ButtonBlack } from '../Form/Form';
+'use client'
+import React from 'react'
+import * as Dialog from '@radix-ui/react-dialog'
+import { styled, keyframes } from '@stitches/react'
+import { blackA, mauve } from '@radix-ui/colors'
+import { ButtonBlack } from '../Form/Form'
type ModalParams = {
- dialogTitle: string;
- dialogDescription: string;
- dialogContent: React.ReactNode;
- dialogClose?: React.ReactNode | null;
- dialogTrigger?: React.ReactNode;
- addDefCloseButton?: boolean;
- onOpenChange: any;
- isDialogOpen?: boolean;
- minHeight?: "sm" | "md" | "lg" | "xl" | "no-min";
-};
+ dialogTitle: string
+ dialogDescription: string
+ dialogContent: React.ReactNode
+ dialogClose?: React.ReactNode | null
+ dialogTrigger?: React.ReactNode
+ addDefCloseButton?: boolean
+ onOpenChange: any
+ isDialogOpen?: boolean
+ minHeight?: 'sm' | 'md' | 'lg' | 'xl' | 'no-min'
+}
const Modal = (params: ModalParams) => (
-
- {params.dialogTrigger ? (
-
- {params.dialogTrigger}
-
+
+ {params.dialogTrigger ? (
+ {params.dialogTrigger}
+ ) : null}
+
+
+
+
+
+ {params.dialogTitle}
+ {params.dialogDescription}
+
+ {params.dialogContent}
+ {params.dialogClose ? (
+
+ {params.dialogClose}
+
) : null}
-
-
-
-
-
- {params.dialogTitle}
-
- {params.dialogDescription}
-
-
- {params.dialogContent}
- {params.dialogClose ? (
-
-
- {params.dialogClose}
-
-
- ) : null}
- {params.addDefCloseButton ? (
-
-
- Close
-
-
- ) : null}
-
-
-
-
-
-);
+ {params.addDefCloseButton ? (
+
+
+
+ Close
+
+
+
+ ) : null}
+
+
+
+)
const overlayShow = keyframes({
- '0%': { opacity: 0 },
- '100%': { opacity: 1 },
-});
+ '0%': { opacity: 0 },
+ '100%': { opacity: 1 },
+})
const overlayClose = keyframes({
- '0%': { opacity: 1 },
- '100%': { opacity: 0 },
-});
+ '0%': { opacity: 1 },
+ '100%': { opacity: 0 },
+})
const contentShow = keyframes({
- '0%': { opacity: 0, transform: 'translate(-50%, -50%) scale(.96)' },
- '100%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' },
-});
+ '0%': { opacity: 0, transform: 'translate(-50%, -50%) scale(.96)' },
+ '100%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' },
+})
const contentClose = keyframes({
- '0%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' },
- '100%': { opacity: 0, transform: 'translate(-50%, -52%) scale(.96)' },
-});
+ '0%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' },
+ '100%': { opacity: 0, transform: 'translate(-50%, -52%) scale(.96)' },
+})
const DialogOverlay = styled(Dialog.Overlay, {
- backgroundColor: blackA.blackA9,
- position: 'fixed',
- zIndex: 500,
- inset: 0,
- animation: `${overlayShow} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
- '&[data-state="closed"]': {
- animation: `${overlayClose} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
- },
-});
+ backgroundColor: blackA.blackA9,
+ position: 'fixed',
+ zIndex: 500,
+ inset: 0,
+ animation: `${overlayShow} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
+ '&[data-state="closed"]': {
+ animation: `${overlayClose} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
+ },
+})
const DialogContent = styled(Dialog.Content, {
-
- variants: {
- minHeight: {
- 'no-min': {
- minHeight: '0px',
- },
- 'sm': {
- minHeight: '300px',
- },
- 'md': {
- minHeight: '500px',
- },
- 'lg': {
- minHeight: '700px',
- },
- 'xl': {
- minHeight: '900px',
- },
- },
+ variants: {
+ minHeight: {
+ 'no-min': {
+ minHeight: '0px',
+ },
+ sm: {
+ minHeight: '300px',
+ },
+ md: {
+ minHeight: '500px',
+ },
+ lg: {
+ minHeight: '700px',
+ },
+ xl: {
+ minHeight: '900px',
+ },
},
+ },
- backgroundColor: 'white',
- borderRadius: 18,
- zIndex: 501,
- boxShadow: 'hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px',
- position: 'fixed',
- top: '50%',
- left: '50%',
- transform: 'translate(-50%, -50%)',
- width: '90vw',
- maxHeight: '85vh',
- minHeight: '300px',
- maxWidth: '600px',
- padding: 11,
- animation: `${contentShow} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
- '&:focus': { outline: 'none' },
+ backgroundColor: 'white',
+ borderRadius: 18,
+ zIndex: 501,
+ boxShadow:
+ 'hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px',
+ position: 'fixed',
+ top: '50%',
+ left: '50%',
+ transform: 'translate(-50%, -50%)',
+ width: '90vw',
+ maxHeight: '85vh',
+ minHeight: '300px',
+ maxWidth: '600px',
+ padding: 11,
+ animation: `${contentShow} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
+ '&:focus': { outline: 'none' },
- '&[data-state="closed"]': {
- animation: `${contentClose} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
- },
- transition: "max-height 0.3s ease-out",
-});
+ '&[data-state="closed"]': {
+ animation: `${contentClose} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
+ },
+ transition: 'max-height 0.3s ease-out',
+})
const DialogTopBar = styled('div', {
- background: "#F7F7F7",
- padding: "8px 14px ",
- borderRadius: 14,
-});
+ background: '#F7F7F7',
+ padding: '8px 14px ',
+ borderRadius: 14,
+})
const DialogTitle = styled(Dialog.Title, {
- margin: 0,
- fontWeight: 700,
- letterSpacing: "-0.05em",
- padding: 0,
- color: mauve.mauve12,
- fontSize: 21,
-});
+ margin: 0,
+ fontWeight: 700,
+ letterSpacing: '-0.05em',
+ padding: 0,
+ color: mauve.mauve12,
+ fontSize: 21,
+})
const DialogDescription = styled(Dialog.Description, {
- color: mauve.mauve11,
- letterSpacing: "-0.03em",
- fontSize: 15,
- padding: 0,
- margin: 0,
-});
+ color: mauve.mauve11,
+ letterSpacing: '-0.03em',
+ fontSize: 15,
+ padding: 0,
+ margin: 0,
+})
-const Flex = styled('div', { display: 'flex' });
+const Flex = styled('div', { display: 'flex' })
-export default Modal;
\ No newline at end of file
+export default Modal
diff --git a/apps/web/components/StyledElements/Titles/TypeOfContentTitle.tsx b/apps/web/components/StyledElements/Titles/TypeOfContentTitle.tsx
index 5030b168..6cfebe68 100644
--- a/apps/web/components/StyledElements/Titles/TypeOfContentTitle.tsx
+++ b/apps/web/components/StyledElements/Titles/TypeOfContentTitle.tsx
@@ -1,32 +1,27 @@
import Image from 'next/image'
-import CoursesLogo from "public/svg/courses.svg";
-import CollectionsLogo from "public/svg/collections.svg";
-import TrailLogo from "public/svg/trail.svg";
+import CoursesLogo from 'public/svg/courses.svg'
+import CollectionsLogo from 'public/svg/collections.svg'
+import TrailLogo from 'public/svg/trail.svg'
-function TypeOfContentTitle(props: { title: string, type: string }) {
-
- function getLogo() {
- if (props.type == "col") {
- return CollectionsLogo;
- }
-
- else if (props.type == "cou") {
- return CoursesLogo;
- }
-
- else if (props.type == "tra") {
- return TrailLogo;
- }
+function TypeOfContentTitle(props: { title: string; type: string }) {
+ function getLogo() {
+ if (props.type == 'col') {
+ return CollectionsLogo
+ } else if (props.type == 'cou') {
+ return CoursesLogo
+ } else if (props.type == 'tra') {
+ return TrailLogo
}
+ }
- return (
-
- )
+ return (
+
+ )
}
-export default TypeOfContentTitle
\ No newline at end of file
+export default TypeOfContentTitle
diff --git a/apps/web/components/StyledElements/Toast/Toast.tsx b/apps/web/components/StyledElements/Toast/Toast.tsx
index e7d43ffe..3ba890c3 100644
--- a/apps/web/components/StyledElements/Toast/Toast.tsx
+++ b/apps/web/components/StyledElements/Toast/Toast.tsx
@@ -1,12 +1,13 @@
-'use client';
+'use client'
import React from 'react'
-import { Toaster } from 'react-hot-toast';
-
+import { Toaster } from 'react-hot-toast'
function Toast() {
- return (
- <>
>
- )
+ return (
+ <>
+
+ >
+ )
}
-export default Toast
\ No newline at end of file
+export default Toast
diff --git a/apps/web/components/StyledElements/Tooltip/Tooltip.tsx b/apps/web/components/StyledElements/Tooltip/Tooltip.tsx
index 200c8232..91495910 100644
--- a/apps/web/components/StyledElements/Tooltip/Tooltip.tsx
+++ b/apps/web/components/StyledElements/Tooltip/Tooltip.tsx
@@ -1,66 +1,65 @@
-'use client';
-import React from 'react';
-import * as Tooltip from '@radix-ui/react-tooltip';
-import { styled, keyframes } from '@stitches/react';
-
+'use client'
+import React from 'react'
+import * as Tooltip from '@radix-ui/react-tooltip'
+import { styled, keyframes } from '@stitches/react'
type TooltipProps = {
- sideOffset?: number;
- content: React.ReactNode;
- children: React.ReactNode;
- side?: 'top' | 'right' | 'bottom' | 'left'; // default is bottom
- slateBlack?: boolean;
-};
+ sideOffset?: number
+ content: React.ReactNode
+ children: React.ReactNode
+ side?: 'top' | 'right' | 'bottom' | 'left' // default is bottom
+ slateBlack?: boolean
+}
const ToolTip = (props: TooltipProps) => {
-
return (
-
- {props.children}
-
+ {props.children}
-
+
{props.content}
- );
-};
+ )
+}
const slideUpAndFade = keyframes({
'0%': { opacity: 0, transform: 'translateY(2px)' },
'100%': { opacity: 1, transform: 'translateY(0)' },
-});
+})
const slideRightAndFade = keyframes({
'0%': { opacity: 0, transform: 'translateX(-2px)' },
'100%': { opacity: 1, transform: 'translateX(0)' },
-});
+})
const slideDownAndFade = keyframes({
'0%': { opacity: 0, transform: 'translateY(-2px)' },
'100%': { opacity: 1, transform: 'translateY(0)' },
-});
+})
const slideLeftAndFade = keyframes({
'0%': { opacity: 0, transform: 'translateX(2px)' },
'100%': { opacity: 1, transform: 'translateX(0)' },
-});
+})
const closeAndFade = keyframes({
'0%': { opacity: 1 },
'100%': { opacity: 0 },
-});
+})
const TooltipContent = styled(Tooltip.Content, {
-
variants: {
slateBlack: {
true: {
- backgroundColor: " #0d0d0d",
+ backgroundColor: ' #0d0d0d',
color: 'white',
},
},
@@ -70,10 +69,11 @@ const TooltipContent = styled(Tooltip.Content, {
padding: '5px 10px',
fontSize: 12,
lineHeight: 1,
- color: "black",
+ color: 'black',
backgroundColor: 'rgba(217, 217, 217, 0.50)',
zIndex: 500,
- boxShadow: 'hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px',
+ boxShadow:
+ 'hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px',
userSelect: 'none',
animationDuration: '400ms',
animationTimingFunction: 'cubic-bezier(0.16, 1, 0.3, 1)',
@@ -92,8 +92,6 @@ const TooltipContent = styled(Tooltip.Content, {
'&[data-side="bottom"]': { animationName: closeAndFade },
'&[data-side="left"]': { animationName: closeAndFade },
},
-});
+})
-
-
-export default ToolTip;
\ No newline at end of file
+export default ToolTip
diff --git a/apps/web/components/StyledElements/Wrappers/GeneralWrapper.tsx b/apps/web/components/StyledElements/Wrappers/GeneralWrapper.tsx
index 9f22d866..00dc7326 100644
--- a/apps/web/components/StyledElements/Wrappers/GeneralWrapper.tsx
+++ b/apps/web/components/StyledElements/Wrappers/GeneralWrapper.tsx
@@ -1,11 +1,9 @@
-
function GeneralWrapperStyled({ children }: { children: React.ReactNode }) {
- return (
-
{children}
- )
+ return (
+
+ {children}
+
+ )
}
-export default GeneralWrapperStyled
\ No newline at end of file
+export default GeneralWrapperStyled
diff --git a/apps/web/components/Utils/ClientComp.tsx b/apps/web/components/Utils/ClientComp.tsx
index 1b1f74ab..b4014623 100644
--- a/apps/web/components/Utils/ClientComp.tsx
+++ b/apps/web/components/Utils/ClientComp.tsx
@@ -1,13 +1,7 @@
-"use client";
+'use client'
-function ClientComponentSkeleton({
- children,
-}: {
- children: React.ReactNode
-}) {
- return (
-
{children}
- )
+function ClientComponentSkeleton({ children }: { children: React.ReactNode }) {
+ return
{children}
}
-export default ClientComponentSkeleton
\ No newline at end of file
+export default ClientComponentSkeleton
diff --git a/apps/web/components/Utils/libs/styled-registry.tsx b/apps/web/components/Utils/libs/styled-registry.tsx
index 663995d4..60ca9991 100644
--- a/apps/web/components/Utils/libs/styled-registry.tsx
+++ b/apps/web/components/Utils/libs/styled-registry.tsx
@@ -1,30 +1,29 @@
+'use client'
-'use client';
-
-import React, { useState } from 'react';
-import { useServerInsertedHTML } from 'next/navigation';
-import { ServerStyleSheet, StyleSheetManager } from 'styled-components';
+import React, { useState } from 'react'
+import { useServerInsertedHTML } from 'next/navigation'
+import { ServerStyleSheet, StyleSheetManager } from 'styled-components'
export default function StyledComponentsRegistry({
children,
}: {
- children: React.ReactNode;
+ children: React.ReactNode
}) {
// Only create stylesheet once with lazy initial state
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
- const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());
+ const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())
useServerInsertedHTML(() => {
- const styles = styledComponentsStyleSheet.getStyleElement();
- styledComponentsStyleSheet.instance.clearTag();
- return <>{styles}>;
- });
+ const styles = styledComponentsStyleSheet.getStyleElement()
+ styledComponentsStyleSheet.instance.clearTag()
+ return <>{styles}>
+ })
- if (typeof window !== 'undefined') return <>{children}>;
+ if (typeof window !== 'undefined') return <>{children}>
return (
{children as React.ReactChild}
- );
-}
\ No newline at end of file
+ )
+}
diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts
index ac547697..0d799d26 100644
--- a/apps/web/middleware.ts
+++ b/apps/web/middleware.ts
@@ -1,7 +1,11 @@
-import { isInstallModeEnabled } from "@services/install/install";
-import { LEARNHOUSE_DOMAIN, getDefaultOrg, isMultiOrgModeEnabled } from "./services/config/config";
-import { NextResponse } from "next/server";
-import type { NextRequest } from "next/server";
+import { isInstallModeEnabled } from '@services/install/install'
+import {
+ LEARNHOUSE_DOMAIN,
+ getDefaultOrg,
+ isMultiOrgModeEnabled,
+} from './services/config/config'
+import { NextResponse } from 'next/server'
+import type { NextRequest } from 'next/server'
export const config = {
matcher: [
@@ -13,49 +17,51 @@ export const config = {
* 4. /examples (inside /public)
* 5. all root files inside /public (e.g. /favicon.ico)
*/
- "/((?!api|_next|fonts|examples|[\\w-]+\\.\\w+).*)",
+ '/((?!api|_next|fonts|examples|[\\w-]+\\.\\w+).*)',
],
-};
+}
export default async function middleware(req: NextRequest) {
// Get initial data
- const hosting_mode = isMultiOrgModeEnabled() ? "multi" : "single";
- const default_org = getDefaultOrg();
- const pathname = req.nextUrl.pathname;
- const fullhost = req.headers ? req.headers.get("host") : "";
+ const hosting_mode = isMultiOrgModeEnabled() ? 'multi' : 'single'
+ const default_org = getDefaultOrg()
+ const pathname = req.nextUrl.pathname
+ const fullhost = req.headers ? req.headers.get('host') : ''
// Organizations & Global settings
- if (pathname.startsWith("/organizations")) {
- return NextResponse.rewrite(new URL(pathname, req.url));
+ if (pathname.startsWith('/organizations')) {
+ return NextResponse.rewrite(new URL(pathname, req.url))
}
// Install Page
- if (pathname.startsWith("/install")) {
+ if (pathname.startsWith('/install')) {
// Check if install mode is enabled
- const install_mode = await isInstallModeEnabled();
+ const install_mode = await isInstallModeEnabled()
if (install_mode) {
- return NextResponse.rewrite(new URL(pathname, req.url));
+ return NextResponse.rewrite(new URL(pathname, req.url))
} else {
- return NextResponse.redirect(new URL("/", req.url));
+ return NextResponse.redirect(new URL('/', req.url))
}
}
// Dynamic Pages Editor
if (pathname.match(/^\/course\/[^/]+\/activity\/[^/]+\/edit$/)) {
- return NextResponse.rewrite(new URL(`/editor${pathname}`, req.url));
+ return NextResponse.rewrite(new URL(`/editor${pathname}`, req.url))
}
// Multi Organization Mode
- if (hosting_mode === "multi") {
+ if (hosting_mode === 'multi') {
// Get the organization slug from the URL
- const orgslug = fullhost ? fullhost.replace(`.${LEARNHOUSE_DOMAIN}`, "") : default_org;
- return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url));
+ const orgslug = fullhost
+ ? fullhost.replace(`.${LEARNHOUSE_DOMAIN}`, '')
+ : default_org
+ return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url))
}
// Single Organization Mode
- if (hosting_mode === "single") {
+ if (hosting_mode === 'single') {
// Get the default organization slug
- const orgslug = default_org;
- return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url));
+ const orgslug = default_org
+ return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url))
}
}
diff --git a/apps/web/sentry.client.config.ts b/apps/web/sentry.client.config.ts
index c128f326..b6aaa736 100644
--- a/apps/web/sentry.client.config.ts
+++ b/apps/web/sentry.client.config.ts
@@ -2,10 +2,10 @@
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
-import * as Sentry from "@sentry/nextjs";
+import * as Sentry from '@sentry/nextjs'
-if (process.env.NODE_ENV !== "development") {
- const DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
+if (process.env.NODE_ENV !== 'development') {
+ const DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
Sentry.init({
dsn: DSN,
@@ -30,5 +30,5 @@ if (process.env.NODE_ENV !== "development") {
blockAllMedia: true,
}),
],
- });
+ })
}
diff --git a/apps/web/sentry.server.config.ts b/apps/web/sentry.server.config.ts
index a2a48ed9..51ab00f5 100644
--- a/apps/web/sentry.server.config.ts
+++ b/apps/web/sentry.server.config.ts
@@ -2,12 +2,12 @@
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
-import * as Sentry from "@sentry/nextjs";
+import * as Sentry from '@sentry/nextjs'
-if (process.env.NODE_ENV !== "development") {
- const DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
+if (process.env.NODE_ENV !== 'development') {
+ const DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
Sentry.init({
dsn: DSN,
tracesSampleRate: 1.0,
- });
+ })
}
diff --git a/apps/web/services/ai/ai.ts b/apps/web/services/ai/ai.ts
index 0344567f..4d1542ce 100644
--- a/apps/web/services/ai/ai.ts
+++ b/apps/web/services/ai/ai.ts
@@ -1,32 +1,65 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody } from '@services/utils/ts/requests'
-export async function startActivityAIChatSession(message: string, activity_uuid: string) {
+export async function startActivityAIChatSession(
+ message: string,
+ activity_uuid: string
+) {
const data = {
message,
activity_uuid,
- };
- const result = await fetch(`${getAPIUrl()}ai/start/activity_chat_session`, RequestBody("POST", data, null));
- const json = await result.json();
+ }
+ const result = await fetch(
+ `${getAPIUrl()}ai/start/activity_chat_session`,
+ RequestBody('POST', data, null)
+ )
+ const json = await result.json()
if (result.status === 200) {
- return { success: true, data: json, status: result.status, HTTPmessage: result.statusText };
+ return {
+ success: true,
+ data: json,
+ status: result.status,
+ HTTPmessage: result.statusText,
+ }
} else {
- return { success: false, data: json, status: result.status, HTTPmessage: result.statusText };
+ return {
+ success: false,
+ data: json,
+ status: result.status,
+ HTTPmessage: result.statusText,
+ }
}
}
-export async function sendActivityAIChatMessage(message: string, aichat_uuid: string, activity_uuid: string) {
+export async function sendActivityAIChatMessage(
+ message: string,
+ aichat_uuid: string,
+ activity_uuid: string
+) {
const data = {
aichat_uuid,
message,
activity_uuid,
- };
- const result = await fetch(`${getAPIUrl()}ai/send/activity_chat_message`, RequestBody("POST", data, null));
+ }
+ const result = await fetch(
+ `${getAPIUrl()}ai/send/activity_chat_message`,
+ RequestBody('POST', data, null)
+ )
- const json = await result.json();
+ const json = await result.json()
if (result.status === 200) {
- return { success: true, data: json, status: result.status, HTTPmessage: result.statusText };
+ return {
+ success: true,
+ data: json,
+ status: result.status,
+ HTTPmessage: result.statusText,
+ }
} else {
- return { success: false, data: json, status: result.status, HTTPmessage: result.statusText };
+ return {
+ success: false,
+ data: json,
+ status: result.status,
+ HTTPmessage: result.statusText,
+ }
}
}
diff --git a/apps/web/services/auth/auth.ts b/apps/web/services/auth/auth.ts
index 38da9485..f18d6002 100644
--- a/apps/web/services/auth/auth.ts
+++ b/apps/web/services/auth/auth.ts
@@ -1,155 +1,182 @@
-import { getAPIUrl } from "@services/config/config";
+import { getAPIUrl } from '@services/config/config'
interface LoginAndGetTokenResponse {
- access_token: "string";
- token_type: "string";
+ access_token: 'string'
+ token_type: 'string'
}
// ⚠️ mvp phase code
// TODO : everything in this file need to be refactored including security issues fix
-export async function loginAndGetToken(username: string, password: string): Promise
{
+export async function loginAndGetToken(
+ username: string,
+ password: string
+): Promise {
// Request Config
// get origin
- const HeadersConfig = new Headers({ "Content-Type": "application/x-www-form-urlencoded" });
- const urlencoded = new URLSearchParams({ username: username, password: password });
+ const HeadersConfig = new Headers({
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ })
+ const urlencoded = new URLSearchParams({
+ username: username,
+ password: password,
+ })
const requestOptions: any = {
- method: "POST",
+ method: 'POST',
headers: HeadersConfig,
body: urlencoded,
- redirect: "follow",
- credentials: "include",
- };
+ redirect: 'follow',
+ credentials: 'include',
+ }
// fetch using await and async
- const response = await fetch(`${getAPIUrl()}auth/login`, requestOptions);
- return response;
+ const response = await fetch(`${getAPIUrl()}auth/login`, requestOptions)
+ return response
}
export async function logout(): Promise {
// Request Config
// get origin
- const HeadersConfig = new Headers({ "Content-Type": "application/x-www-form-urlencoded" });
- const urlencoded = new URLSearchParams();
+ const HeadersConfig = new Headers({
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ })
+ const urlencoded = new URLSearchParams()
const requestOptions: any = {
- method: "DELETE",
+ method: 'DELETE',
headers: HeadersConfig,
body: urlencoded,
- redirect: "follow",
- credentials: "include",
- };
+ redirect: 'follow',
+ credentials: 'include',
+ }
// fetch using await and async
- const response = await fetch(`${getAPIUrl()}auth/logout`, requestOptions);
- return response;
+ const response = await fetch(`${getAPIUrl()}auth/logout`, requestOptions)
+ return response
}
export async function getUserInfo(token: string): Promise {
- const origin = window.location.origin;
- const HeadersConfig = new Headers({ Authorization: `Bearer ${token}`, Origin: origin });
+ const origin = window.location.origin
+ const HeadersConfig = new Headers({
+ Authorization: `Bearer ${token}`,
+ Origin: origin,
+ })
const requestOptions: any = {
- method: "GET",
+ method: 'GET',
headers: HeadersConfig,
- redirect: "follow",
- credentials: "include",
- };
+ redirect: 'follow',
+ credentials: 'include',
+ }
return fetch(`${getAPIUrl()}users/profile`, requestOptions)
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
export async function getUserSession(token: string): Promise {
- const origin = window.location.origin;
- const HeadersConfig = new Headers({ Authorization: `Bearer ${token}`, Origin: origin });
+ const origin = window.location.origin
+ const HeadersConfig = new Headers({
+ Authorization: `Bearer ${token}`,
+ Origin: origin,
+ })
const requestOptions: any = {
- method: "GET",
+ method: 'GET',
headers: HeadersConfig,
- redirect: "follow",
- credentials: "include",
- };
+ redirect: 'follow',
+ credentials: 'include',
+ }
return fetch(`${getAPIUrl()}users/session`, requestOptions)
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
export async function getNewAccessTokenUsingRefreshToken(): Promise {
const requestOptions: any = {
- method: "GET",
- redirect: "follow",
- credentials: "include",
- };
+ method: 'GET',
+ redirect: 'follow',
+ credentials: 'include',
+ }
return fetch(`${getAPIUrl()}auth/refresh`, requestOptions)
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
-export async function getNewAccessTokenUsingRefreshTokenServer(refresh_token_cookie: any): Promise {
+export async function getNewAccessTokenUsingRefreshTokenServer(
+ refresh_token_cookie: any
+): Promise {
const requestOptions: any = {
- method: "GET",
- redirect: "follow",
+ method: 'GET',
+ redirect: 'follow',
headers: {
Cookie: `refresh_token_cookie=${refresh_token_cookie}`,
},
- credentials: "include",
- };
+ credentials: 'include',
+ }
return fetch(`${getAPIUrl()}auth/refresh`, requestOptions)
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
// cookies
export async function getAccessTokenFromRefreshTokenCookie(cookieStore: any) {
- const refresh_token_cookie: any = cookieStore.get("refresh_token_cookie");
- const access_token_cookie: any = await getNewAccessTokenUsingRefreshTokenServer(refresh_token_cookie?.value);
- return access_token_cookie && refresh_token_cookie ? access_token_cookie.access_token : null;
+ const refresh_token_cookie: any = cookieStore.get('refresh_token_cookie')
+ const access_token_cookie: any =
+ await getNewAccessTokenUsingRefreshTokenServer(refresh_token_cookie?.value)
+ return access_token_cookie && refresh_token_cookie
+ ? access_token_cookie.access_token
+ : null
}
// signup
interface NewAccountBody {
- username: string;
- email: string;
- password: string;
- org_slug: string;
- org_id:string;
+ username: string
+ email: string
+ password: string
+ org_slug: string
+ org_id: string
}
export async function signup(body: NewAccountBody): Promise {
- const HeadersConfig = new Headers({ "Content-Type": "application/json" });
+ const HeadersConfig = new Headers({ 'Content-Type': 'application/json' })
const requestOptions: any = {
- method: "POST",
+ method: 'POST',
headers: HeadersConfig,
body: JSON.stringify(body),
- redirect: "follow",
- };
+ redirect: 'follow',
+ }
- const res = await fetch(`${getAPIUrl()}users/${body.org_id}`, requestOptions);
-
- return res;
+ const res = await fetch(`${getAPIUrl()}users/${body.org_id}`, requestOptions)
+
+ return res
}
-export async function signUpWithInviteCode(body: NewAccountBody,invite_code:string): Promise {
- const HeadersConfig = new Headers({ "Content-Type": "application/json" });
+export async function signUpWithInviteCode(
+ body: NewAccountBody,
+ invite_code: string
+): Promise {
+ const HeadersConfig = new Headers({ 'Content-Type': 'application/json' })
const requestOptions: any = {
- method: "POST",
+ method: 'POST',
headers: HeadersConfig,
body: JSON.stringify(body),
- redirect: "follow",
- };
+ redirect: 'follow',
+ }
- const res = await fetch(`${getAPIUrl()}users/${body.org_id}/invite/${invite_code}`, requestOptions);
-
- return res;
+ const res = await fetch(
+ `${getAPIUrl()}users/${body.org_id}/invite/${invite_code}`,
+ requestOptions
+ )
+
+ return res
}
diff --git a/apps/web/services/blocks/Image/images.ts b/apps/web/services/blocks/Image/images.ts
index e79777c7..6a578adf 100644
--- a/apps/web/services/blocks/Image/images.ts
+++ b/apps/web/services/blocks/Image/images.ts
@@ -1,20 +1,26 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, RequestBodyForm } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, RequestBodyForm } from '@services/utils/ts/requests'
export async function uploadNewImageFile(file: any, activity_uuid: string) {
// Send file thumbnail as form data
- const formData = new FormData();
- formData.append("file_object", file);
- formData.append("activity_uuid", activity_uuid);
+ const formData = new FormData()
+ formData.append('file_object', file)
+ formData.append('activity_uuid', activity_uuid)
- return fetch(`${getAPIUrl()}blocks/image`, RequestBodyForm("POST", formData, null))
+ return fetch(
+ `${getAPIUrl()}blocks/image`,
+ RequestBodyForm('POST', formData, null)
+ )
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
export async function getImageFile(file_id: string) {
// todo : add course id to url
- return fetch(`${getAPIUrl()}blocks/image?file_id=${file_id}`, RequestBody("GET", null, null))
+ return fetch(
+ `${getAPIUrl()}blocks/image?file_id=${file_id}`,
+ RequestBody('GET', null, null)
+ )
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
diff --git a/apps/web/services/blocks/Pdf/pdf.ts b/apps/web/services/blocks/Pdf/pdf.ts
index beafbeb0..06b053c7 100644
--- a/apps/web/services/blocks/Pdf/pdf.ts
+++ b/apps/web/services/blocks/Pdf/pdf.ts
@@ -1,20 +1,26 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, RequestBodyForm } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, RequestBodyForm } from '@services/utils/ts/requests'
export async function uploadNewPDFFile(file: any, activity_uuid: string) {
// Send file thumbnail as form data
- const formData = new FormData();
- formData.append("file_object", file);
- formData.append("activity_uuid", activity_uuid);
+ const formData = new FormData()
+ formData.append('file_object', file)
+ formData.append('activity_uuid', activity_uuid)
- return fetch(`${getAPIUrl()}blocks/pdf`, RequestBodyForm("POST", formData, null))
+ return fetch(
+ `${getAPIUrl()}blocks/pdf`,
+ RequestBodyForm('POST', formData, null)
+ )
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
export async function getPDFFile(file_id: string) {
// todo : add course id to url
- return fetch(`${getAPIUrl()}blocks/pdf?file_id=${file_id}`, RequestBody("GET", null, null))
+ return fetch(
+ `${getAPIUrl()}blocks/pdf?file_id=${file_id}`,
+ RequestBody('GET', null, null)
+ )
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
diff --git a/apps/web/services/blocks/Quiz/quiz.ts b/apps/web/services/blocks/Quiz/quiz.ts
index 83d19de8..0928ffd5 100644
--- a/apps/web/services/blocks/Quiz/quiz.ts
+++ b/apps/web/services/blocks/Quiz/quiz.ts
@@ -1,10 +1,12 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody } from "@services/utils/ts/requests";
-
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody } from '@services/utils/ts/requests'
export async function submitQuizBlock(activity_id: string, data: any) {
- const result: any = await fetch(`${getAPIUrl()}blocks/quiz/${activity_id}"`, RequestBody("POST", data, null))
+ const result: any = await fetch(
+ `${getAPIUrl()}blocks/quiz/${activity_id}"`,
+ RequestBody('POST', data, null)
+ )
.then((result) => result.json())
- .catch((error) => console.log("error", error));
- return result;
-}
\ No newline at end of file
+ .catch((error) => console.log('error', error))
+ return result
+}
diff --git a/apps/web/services/blocks/Video/video.ts b/apps/web/services/blocks/Video/video.ts
index fb0389ff..fff4a502 100644
--- a/apps/web/services/blocks/Video/video.ts
+++ b/apps/web/services/blocks/Video/video.ts
@@ -1,19 +1,25 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, RequestBodyForm } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, RequestBodyForm } from '@services/utils/ts/requests'
export async function uploadNewVideoFile(file: any, activity_uuid: string) {
// Send file thumbnail as form data
- const formData = new FormData();
- formData.append("file_object", file);
- formData.append("activity_uuid", activity_uuid);
+ const formData = new FormData()
+ formData.append('file_object', file)
+ formData.append('activity_uuid', activity_uuid)
- return fetch(`${getAPIUrl()}blocks/video`, RequestBodyForm("POST", formData, null))
+ return fetch(
+ `${getAPIUrl()}blocks/video`,
+ RequestBodyForm('POST', formData, null)
+ )
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
export async function getVideoFile(file_id: string) {
- return fetch(`${getAPIUrl()}blocks/video?file_id=${file_id}`, RequestBody("GET", null, null))
+ return fetch(
+ `${getAPIUrl()}blocks/video?file_id=${file_id}`,
+ RequestBody('GET', null, null)
+ )
.then((result) => result.json())
- .catch((error) => console.log("error", error));
+ .catch((error) => console.log('error', error))
}
diff --git a/apps/web/services/config/config.ts b/apps/web/services/config/config.ts
index caab8422..732cf31f 100644
--- a/apps/web/services/config/config.ts
+++ b/apps/web/services/config/config.ts
@@ -1,35 +1,37 @@
-export const LEARNHOUSE_HTTP_PROTOCOL = process.env.NEXT_PUBLIC_LEARNHOUSE_HTTPS === "true" ? "https://" : "http://";
-const LEARNHOUSE_API_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_API_URL}`;
-export const LEARNHOUSE_BACKEND_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}`;
-export const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN;
+export const LEARNHOUSE_HTTP_PROTOCOL =
+ process.env.NEXT_PUBLIC_LEARNHOUSE_HTTPS === 'true' ? 'https://' : 'http://'
+const LEARNHOUSE_API_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_API_URL}`
+export const LEARNHOUSE_BACKEND_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}`
+export const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN
-export const getAPIUrl = () => LEARNHOUSE_API_URL;
-export const getBackendUrl = () => LEARNHOUSE_BACKEND_URL;
+export const getAPIUrl = () => LEARNHOUSE_API_URL
+export const getBackendUrl = () => LEARNHOUSE_BACKEND_URL
// Multi Organization Mode
-export const isMultiOrgModeEnabled = () => (process.env.NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG === "true" ? true : false);
+export const isMultiOrgModeEnabled = () =>
+ process.env.NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG === 'true' ? true : false
export const getUriWithOrg = (orgslug: string, path: string) => {
- const multi_org = isMultiOrgModeEnabled();
+ const multi_org = isMultiOrgModeEnabled()
if (multi_org) {
- return `${LEARNHOUSE_HTTP_PROTOCOL}${orgslug}.${LEARNHOUSE_DOMAIN}${path}`;
+ return `${LEARNHOUSE_HTTP_PROTOCOL}${orgslug}.${LEARNHOUSE_DOMAIN}${path}`
}
- return `${LEARNHOUSE_HTTP_PROTOCOL}${LEARNHOUSE_DOMAIN}${path}`;
-};
+ return `${LEARNHOUSE_HTTP_PROTOCOL}${LEARNHOUSE_DOMAIN}${path}`
+}
export const getOrgFromUri = () => {
- const multi_org = isMultiOrgModeEnabled();
+ const multi_org = isMultiOrgModeEnabled()
if (multi_org) {
- getDefaultOrg();
+ getDefaultOrg()
} else {
- if (typeof window !== "undefined") {
- const hostname = window.location.hostname;
+ if (typeof window !== 'undefined') {
+ const hostname = window.location.hostname
- return hostname.replace(`.${LEARNHOUSE_DOMAIN}`, "");
+ return hostname.replace(`.${LEARNHOUSE_DOMAIN}`, '')
}
}
-};
+}
export const getDefaultOrg = () => {
- return process.env.NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG;
-};
+ return process.env.NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG
+}
diff --git a/apps/web/services/courses/activities.ts b/apps/web/services/courses/activities.ts
index 750a524f..1c8748a9 100644
--- a/apps/web/services/courses/activities.ts
+++ b/apps/web/services/courses/activities.ts
@@ -1,70 +1,108 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, RequestBodyForm, RequestBodyWithAuthHeader } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import {
+ RequestBody,
+ RequestBodyForm,
+ RequestBodyWithAuthHeader,
+} from '@services/utils/ts/requests'
export async function createActivity(data: any, chapter_id: any, org_id: any) {
- data.content = {};
+ data.content = {}
// remove chapter_id from data
- delete data.chapterId;
+ delete data.chapterId
- const result = await fetch(`${getAPIUrl()}activities/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data, null));
- const res = await result.json();
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}activities/?coursechapter_id=${chapter_id}&org_id=${org_id}`,
+ RequestBody('POST', data, null)
+ )
+ const res = await result.json()
+ return res
}
-export async function createFileActivity(file: File, type: string, data: any, chapter_id: any) {
+export async function createFileActivity(
+ file: File,
+ type: string,
+ data: any,
+ chapter_id: any
+) {
// Send file thumbnail as form data
- const formData = new FormData();
- formData.append("chapter_id", chapter_id);
+ const formData = new FormData()
+ formData.append('chapter_id', chapter_id)
- let endpoint = "";
+ let endpoint = ''
- if (type === "video") {
- formData.append("name", data.name);
- formData.append("video_file", file);
- endpoint = `${getAPIUrl()}activities/video`;
- } else if (type === "documentpdf") {
- formData.append("pdf_file", file);
- formData.append("name", data.name);
- endpoint = `${getAPIUrl()}activities/documentpdf`;
+ if (type === 'video') {
+ formData.append('name', data.name)
+ formData.append('video_file', file)
+ endpoint = `${getAPIUrl()}activities/video`
+ } else if (type === 'documentpdf') {
+ formData.append('pdf_file', file)
+ formData.append('name', data.name)
+ endpoint = `${getAPIUrl()}activities/documentpdf`
} else {
// Handle other file types here
}
- const result: any = await fetch(endpoint, RequestBodyForm("POST", formData, null));
- const res = await result.json();
- return res;
+ const result: any = await fetch(
+ endpoint,
+ RequestBodyForm('POST', formData, null)
+ )
+ const res = await result.json()
+ return res
}
-export async function createExternalVideoActivity(data: any, activity: any, chapter_id: any) {
+export async function createExternalVideoActivity(
+ data: any,
+ activity: any,
+ chapter_id: any
+) {
// add coursechapter_id to data
- data.chapter_id = chapter_id;
- data.activity_id = activity.id;
+ data.chapter_id = chapter_id
+ data.activity_id = activity.id
- const result = await fetch(`${getAPIUrl()}activities/external_video`, RequestBody("POST", data, null));
- const res = await result.json();
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}activities/external_video`,
+ RequestBody('POST', data, null)
+ )
+ const res = await result.json()
+ return res
}
export async function getActivity(activity_id: any, next: any) {
- const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null, next));
- const res = await result.json();
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}activities/${activity_id}`,
+ RequestBody('GET', null, next)
+ )
+ const res = await result.json()
+ return res
}
export async function deleteActivity(activity_id: any) {
- const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("DELETE", null, null));
- const res = await result.json();
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}activities/${activity_id}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await result.json()
+ return res
}
-export async function getActivityWithAuthHeader(activity_uuid: any, next: any, access_token: string) {
- const result = await fetch(`${getAPIUrl()}activities/activity_${activity_uuid}`, RequestBodyWithAuthHeader("GET", null, next, access_token));
- const res = await result.json();
- return res;
+export async function getActivityWithAuthHeader(
+ activity_uuid: any,
+ next: any,
+ access_token: string
+) {
+ const result = await fetch(
+ `${getAPIUrl()}activities/activity_${activity_uuid}`,
+ RequestBodyWithAuthHeader('GET', null, next, access_token)
+ )
+ const res = await result.json()
+ return res
}
export async function updateActivity(data: any, activity_uuid: string) {
- const result = await fetch(`${getAPIUrl()}activities/${activity_uuid}`, RequestBody("PUT", data, null));
- const res = await result.json();
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}activities/${activity_uuid}`,
+ RequestBody('PUT', data, null)
+ )
+ const res = await result.json()
+ return res
}
diff --git a/apps/web/services/courses/activity.ts b/apps/web/services/courses/activity.ts
index bdcf3368..8b0e7838 100644
--- a/apps/web/services/courses/activity.ts
+++ b/apps/web/services/courses/activity.ts
@@ -1,5 +1,5 @@
-import { RequestBody, errorHandling } from "@services/utils/ts/requests";
-import { getAPIUrl } from "@services/config/config";
+import { RequestBody, errorHandling } from '@services/utils/ts/requests'
+import { getAPIUrl } from '@services/config/config'
/*
This file includes only POST, PUT, DELETE requests
@@ -7,19 +7,32 @@ import { getAPIUrl } from "@services/config/config";
*/
export async function startCourse(course_uuid: string, org_slug: string) {
- const result: any = await fetch(`${getAPIUrl()}trail/add_course/${course_uuid}`, RequestBody("POST", null, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}trail/add_course/${course_uuid}`,
+ RequestBody('POST', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function removeCourse(course_uuid: string, org_slug: string) {
- const result: any = await fetch(`${getAPIUrl()}trail/remove_course/${course_uuid}`, RequestBody("DELETE", null, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}trail/remove_course/${course_uuid}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function markActivityAsComplete(org_slug: string, course_uuid: string, activity_uuid: string) {
- const result: any = await fetch(`${getAPIUrl()}trail/add_activity/${activity_uuid}`, RequestBody("POST", null, null));
- const res = await errorHandling(result);
- return res;
+export async function markActivityAsComplete(
+ org_slug: string,
+ course_uuid: string,
+ activity_uuid: string
+) {
+ const result: any = await fetch(
+ `${getAPIUrl()}trail/add_activity/${activity_uuid}`,
+ RequestBody('POST', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
diff --git a/apps/web/services/courses/chapters.ts b/apps/web/services/courses/chapters.ts
index 23f1207d..58ed5d1f 100644
--- a/apps/web/services/courses/chapters.ts
+++ b/apps/web/services/courses/chapters.ts
@@ -1,6 +1,6 @@
-import { OrderPayload } from "@components/Dashboard/Course/EditCourseStructure/EditCourseStructure";
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, errorHandling } from "@services/utils/ts/requests";
+import { OrderPayload } from '@components/Dashboard/Course/EditCourseStructure/EditCourseStructure'
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, errorHandling } from '@services/utils/ts/requests'
/*
This file includes only POST, PUT, DELETE requests
@@ -9,38 +9,59 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests";
//TODO : depreciate this function
export async function getCourseChaptersMetadata(course_uuid: any, next: any) {
- const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_uuid}`, RequestBody("GET", null, next));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}chapters/meta/course_${course_uuid}`,
+ RequestBody('GET', null, next)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function updateChaptersMetadata(course_uuid: any, data: any) {
- const result: any = await fetch(`${getAPIUrl()}chapters/course/course_${course_uuid}/order`, RequestBody("PUT", data, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}chapters/course/course_${course_uuid}/order`,
+ RequestBody('PUT', data, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function updateChapter(coursechapter_id: any, data: any) {
- const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("PUT", data, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}chapters/${coursechapter_id}`,
+ RequestBody('PUT', data, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function updateCourseOrderStructure(course_uuid: any, data: OrderPayload) {
- const result: any = await fetch(`${getAPIUrl()}chapters/course/${course_uuid}/order`, RequestBody("PUT", data, null));
- const res = await errorHandling(result);
- return res;
+export async function updateCourseOrderStructure(
+ course_uuid: any,
+ data: OrderPayload
+) {
+ const result: any = await fetch(
+ `${getAPIUrl()}chapters/course/${course_uuid}/order`,
+ RequestBody('PUT', data, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function createChapter(data: any) {
- const result: any = await fetch(`${getAPIUrl()}chapters/`, RequestBody("POST", data, null));
- const res = await errorHandling(result);
+ const result: any = await fetch(
+ `${getAPIUrl()}chapters/`,
+ RequestBody('POST', data, null)
+ )
+ const res = await errorHandling(result)
- return res;
+ return res
}
export async function deleteChapter(coursechapter_id: any) {
- const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("DELETE", null, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}chapters/${coursechapter_id}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
diff --git a/apps/web/services/courses/collections.ts b/apps/web/services/courses/collections.ts
index 63f53ea7..84575309 100644
--- a/apps/web/services/courses/collections.ts
+++ b/apps/web/services/courses/collections.ts
@@ -1,5 +1,9 @@
-import { getAPIUrl } from "../config/config";
-import { RequestBody, RequestBodyWithAuthHeader, errorHandling } from "@services/utils/ts/requests";
+import { getAPIUrl } from '../config/config'
+import {
+ RequestBody,
+ RequestBodyWithAuthHeader,
+ errorHandling,
+} from '@services/utils/ts/requests'
/*
This file includes only POST, PUT, DELETE requests
@@ -7,41 +11,66 @@ import { RequestBody, RequestBodyWithAuthHeader, errorHandling } from "@services
*/
export async function deleteCollection(collection_uuid: any) {
- const result: any = await fetch(`${getAPIUrl()}collections/${collection_uuid}`, RequestBody("DELETE", null, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}collections/${collection_uuid}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
// Create a new collection
export async function createCollection(collection: any) {
- const result: any = await fetch(`${getAPIUrl()}collections/`, RequestBody("POST", collection, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}collections/`,
+ RequestBody('POST', collection, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
// Get a colletion by id
export async function getCollectionById(collection_uuid: any) {
- const result: any = await fetch(`${getAPIUrl()}collections/${collection_uuid}`, { next: { revalidate: 10 } });
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}collections/${collection_uuid}`,
+ { next: { revalidate: 10 } }
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function getCollectionByIdWithAuthHeader(collection_uuid: any, access_token: string, next: any) {
- const result: any = await fetch(`${getAPIUrl()}collections/collection_${collection_uuid}`, RequestBodyWithAuthHeader("GET", null, next, access_token));
- const res = await errorHandling(result);
- return res;
+export async function getCollectionByIdWithAuthHeader(
+ collection_uuid: any,
+ access_token: string,
+ next: any
+) {
+ const result: any = await fetch(
+ `${getAPIUrl()}collections/collection_${collection_uuid}`,
+ RequestBodyWithAuthHeader('GET', null, next, access_token)
+ )
+ const res = await errorHandling(result)
+ return res
}
// Get collections
// TODO : add per org filter
export async function getOrgCollections() {
- const result: any = await fetch(`${getAPIUrl()}collections/page/1/limit/10`, { next: { revalidate: 10 } });
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(`${getAPIUrl()}collections/page/1/limit/10`, {
+ next: { revalidate: 10 },
+ })
+ const res = await errorHandling(result)
+ return res
}
-export async function getOrgCollectionsWithAuthHeader(org_id: string, access_token: string, next: any) {
- const result: any = await fetch(`${getAPIUrl()}collections/org/${org_id}/page/1/limit/10`, RequestBodyWithAuthHeader("GET", null, next, access_token));
- const res = await errorHandling(result);
- return res;
+export async function getOrgCollectionsWithAuthHeader(
+ org_id: string,
+ access_token: string,
+ next: any
+) {
+ const result: any = await fetch(
+ `${getAPIUrl()}collections/org/${org_id}/page/1/limit/10`,
+ RequestBodyWithAuthHeader('GET', null, next, access_token)
+ )
+ const res = await errorHandling(result)
+ return res
}
diff --git a/apps/web/services/courses/courses.ts b/apps/web/services/courses/courses.ts
index 200557de..3e32968a 100644
--- a/apps/web/services/courses/courses.ts
+++ b/apps/web/services/courses/courses.ts
@@ -1,5 +1,11 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, RequestBodyForm, RequestBodyWithAuthHeader, errorHandling, getResponseMetadata } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import {
+ RequestBody,
+ RequestBodyForm,
+ RequestBodyWithAuthHeader,
+ errorHandling,
+ getResponseMetadata,
+} from '@services/utils/ts/requests'
/*
This file includes only POST, PUT, DELETE requests
@@ -7,64 +13,100 @@ import { RequestBody, RequestBodyForm, RequestBodyWithAuthHeader, errorHandling,
*/
export async function getOrgCourses(org_id: number, next: any) {
- const result: any = await fetch(`${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`, RequestBody("GET", null, next));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`,
+ RequestBody('GET', null, next)
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function getOrgCoursesWithAuthHeader(org_id: number, next: any, access_token: string) {
- const result: any = await fetch(`${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`, RequestBodyWithAuthHeader("GET", null, next, access_token));
- const res = await errorHandling(result);
- return res;
+export async function getOrgCoursesWithAuthHeader(
+ org_id: number,
+ next: any,
+ access_token: string
+) {
+ const result: any = await fetch(
+ `${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`,
+ RequestBodyWithAuthHeader('GET', null, next, access_token)
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function getCourseMetadataWithAuthHeader(course_uuid: any, next: any, access_token: string) {
- const result = await fetch(`${getAPIUrl()}courses/course_${course_uuid}/meta`, RequestBodyWithAuthHeader("GET", null, next, access_token));
- const res = await errorHandling(result);
- return res;
+export async function getCourseMetadataWithAuthHeader(
+ course_uuid: any,
+ next: any,
+ access_token: string
+) {
+ const result = await fetch(
+ `${getAPIUrl()}courses/course_${course_uuid}/meta`,
+ RequestBodyWithAuthHeader('GET', null, next, access_token)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function updateCourse(course_uuid: any, data: any) {
- const result: any = await fetch(`${getAPIUrl()}courses/${course_uuid}`, RequestBody("PUT", data, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}courses/${course_uuid}`,
+ RequestBody('PUT', data, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function getCourse(course_uuid: string, next: any) {
- const result: any = await fetch(`${getAPIUrl()}courses/${course_uuid}`, RequestBody("GET", null, next));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}courses/${course_uuid}`,
+ RequestBody('GET', null, next)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function updateCourseThumbnail(course_uuid: any, thumbnail: any) {
- const formData = new FormData();
- formData.append("thumbnail", thumbnail);
- const result: any = await fetch(`${getAPIUrl()}courses/${course_uuid}/thumbnail`, RequestBodyForm("PUT", formData, null));
- const res = await getResponseMetadata(result);
- return res;
+ const formData = new FormData()
+ formData.append('thumbnail', thumbnail)
+ const result: any = await fetch(
+ `${getAPIUrl()}courses/${course_uuid}/thumbnail`,
+ RequestBodyForm('PUT', formData, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
}
-export async function createNewCourse(org_id: string, course_body: any, thumbnail: any) {
+export async function createNewCourse(
+ org_id: string,
+ course_body: any,
+ thumbnail: any
+) {
// Send file thumbnail as form data
- const formData = new FormData();
- formData.append("name", course_body.name);
- formData.append("description", course_body.description);
- formData.append("public", course_body.visibility);
- formData.append("learnings", course_body.tags);
- formData.append("tags", course_body.tags);
- formData.append("about", course_body.description);
+ const formData = new FormData()
+ formData.append('name', course_body.name)
+ formData.append('description', course_body.description)
+ formData.append('public', course_body.visibility)
+ formData.append('learnings', course_body.tags)
+ formData.append('tags', course_body.tags)
+ formData.append('about', course_body.description)
if (thumbnail) {
- formData.append("thumbnail", thumbnail);
+ formData.append('thumbnail', thumbnail)
}
- const result = await fetch(`${getAPIUrl()}courses/?org_id=${org_id}`, RequestBodyForm("POST", formData, null));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}courses/?org_id=${org_id}`,
+ RequestBodyForm('POST', formData, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function deleteCourseFromBackend(course_uuid: any) {
- const result: any = await fetch(`${getAPIUrl()}courses/${course_uuid}`, RequestBody("DELETE", null, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}courses/${course_uuid}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
diff --git a/apps/web/services/install/install.ts b/apps/web/services/install/install.ts
index b0b0adb3..e06e814f 100644
--- a/apps/web/services/install/install.ts
+++ b/apps/web/services/install/install.ts
@@ -1,42 +1,62 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, errorHandling } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, errorHandling } from '@services/utils/ts/requests'
export async function updateInstall(body: any, step: number) {
- const result = await fetch(`${getAPIUrl()}install/update?step=${step}`, RequestBody("POST", body, null));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}install/update?step=${step}`,
+ RequestBody('POST', body, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function createNewOrgInstall(body: any) {
- const result = await fetch(`${getAPIUrl()}install/org`, RequestBody("POST", body, null));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}install/org`,
+ RequestBody('POST', body, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function createNewUserInstall(body: any,org_slug:string) {
- const result = await fetch(`${getAPIUrl()}install/user?org_slug=${org_slug}`, RequestBody("POST", body, null));
- const res = await errorHandling(result);
- return res;
+export async function createNewUserInstall(body: any, org_slug: string) {
+ const result = await fetch(
+ `${getAPIUrl()}install/user?org_slug=${org_slug}`,
+ RequestBody('POST', body, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function createSampleDataInstall(username: string, org_slug: string) {
- const result = await fetch(`${getAPIUrl()}install/sample?username=${username}&org_slug=${org_slug}`, RequestBody("POST", null, null));
- const res = await errorHandling(result);
- return res;
+export async function createSampleDataInstall(
+ username: string,
+ org_slug: string
+) {
+ const result = await fetch(
+ `${getAPIUrl()}install/sample?username=${username}&org_slug=${org_slug}`,
+ RequestBody('POST', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function createDefaultElements() {
- const result = await fetch(`${getAPIUrl()}install/default_elements`, RequestBody("POST", null, null));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}install/default_elements`,
+ RequestBody('POST', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function isInstallModeEnabled() {
- const result = await fetch(`${getAPIUrl()}install/latest`, RequestBody("GET", null, null));
+ const result = await fetch(
+ `${getAPIUrl()}install/latest`,
+ RequestBody('GET', null, null)
+ )
if (result.status === 200 || result.status === 404) {
- return true;
- }
- else {
- return false;
+ return true
+ } else {
+ return false
}
}
diff --git a/apps/web/services/media/media.ts b/apps/web/services/media/media.ts
index c99161d9..9a7cb31a 100644
--- a/apps/web/services/media/media.ts
+++ b/apps/web/services/media/media.ts
@@ -1,51 +1,68 @@
-import { getBackendUrl } from "@services/config/config";
-const LEARNHOUSE_MEDIA_URL = process.env.NEXT_PUBLIC_LEARNHOUSE_MEDIA_URL;
+import { getBackendUrl } from '@services/config/config'
+const LEARNHOUSE_MEDIA_URL = process.env.NEXT_PUBLIC_LEARNHOUSE_MEDIA_URL
function getMediaUrl() {
if (LEARNHOUSE_MEDIA_URL) {
- return LEARNHOUSE_MEDIA_URL;
+ return LEARNHOUSE_MEDIA_URL
} else {
- return getBackendUrl();
+ return getBackendUrl()
}
}
-export function getCourseThumbnailMediaDirectory(orgUUID: string, courseId: string, fileId: string) {
- let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/thumbnails/${fileId}`;
- return uri;
+export function getCourseThumbnailMediaDirectory(
+ orgUUID: string,
+ courseId: string,
+ fileId: string
+) {
+ let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/thumbnails/${fileId}`
+ return uri
}
export function getUserAvatarMediaDirectory(userUUID: string, fileId: string) {
- let uri = `${getMediaUrl()}content/users/${userUUID}/avatars/${fileId}`;
- return uri;
+ let uri = `${getMediaUrl()}content/users/${userUUID}/avatars/${fileId}`
+ return uri
}
-export function getActivityBlockMediaDirectory(orgUUID: string, courseId: string, activityId: string, blockId: any, fileId: any, type: string) {
- if (type == "pdfBlock") {
- let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/dynamic/blocks/pdfBlock/${blockId}/${fileId}`;
- return uri;
+export function getActivityBlockMediaDirectory(
+ orgUUID: string,
+ courseId: string,
+ activityId: string,
+ blockId: any,
+ fileId: any,
+ type: string
+) {
+ if (type == 'pdfBlock') {
+ let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/dynamic/blocks/pdfBlock/${blockId}/${fileId}`
+ return uri
}
- if (type == "videoBlock") {
- let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/dynamic/blocks/videoBlock/${blockId}/${fileId}`;
- return uri;
+ if (type == 'videoBlock') {
+ let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/dynamic/blocks/videoBlock/${blockId}/${fileId}`
+ return uri
}
- if (type == "imageBlock") {
- let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/dynamic/blocks/imageBlock/${blockId}/${fileId}`;
- return uri;
+ if (type == 'imageBlock') {
+ let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/dynamic/blocks/imageBlock/${blockId}/${fileId}`
+ return uri
}
}
-export function getActivityMediaDirectory(orgUUID: string, courseId: string, activityId: string, fileId: string, activityType: string) {
- if (activityType == "video") {
- let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/video/${fileId}`;
- return uri;
+export function getActivityMediaDirectory(
+ orgUUID: string,
+ courseId: string,
+ activityId: string,
+ fileId: string,
+ activityType: string
+) {
+ if (activityType == 'video') {
+ let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/video/${fileId}`
+ return uri
}
- if (activityType == "documentpdf") {
- let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/documentpdf/${fileId}`;
- return uri;
+ if (activityType == 'documentpdf') {
+ let uri = `${getMediaUrl()}content/orgs/${orgUUID}/courses/${courseId}/activities/${activityId}/documentpdf/${fileId}`
+ return uri
}
}
export function getOrgLogoMediaDirectory(orgUUID: string, fileId: string) {
- let uri = `${getMediaUrl()}content/orgs/${orgUUID}/logos/${fileId}`;
- return uri;
+ let uri = `${getMediaUrl()}content/orgs/${orgUUID}/logos/${fileId}`
+ return uri
}
diff --git a/apps/web/services/organizations/invites.ts b/apps/web/services/organizations/invites.ts
index 256cb612..cdaca243 100644
--- a/apps/web/services/organizations/invites.ts
+++ b/apps/web/services/organizations/invites.ts
@@ -1,26 +1,44 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, getResponseMetadata } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, getResponseMetadata } from '@services/utils/ts/requests'
export async function createInviteCode(org_id: any) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}/invites`, RequestBody("POST", null, null));
- const res = await getResponseMetadata(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}/invites`,
+ RequestBody('POST', null, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
}
-export async function deleteInviteCode(org_id: any, org_invite_code_uuid: string) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}/invites/${org_invite_code_uuid}`, RequestBody("DELETE", null, null));
- const res = await getResponseMetadata(result);
- return res;
+export async function deleteInviteCode(
+ org_id: any,
+ org_invite_code_uuid: string
+) {
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}/invites/${org_invite_code_uuid}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
}
-export async function changeSignupMechanism(org_id: any, signup_mechanism: string) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}/signup_mechanism?signup_mechanism=${signup_mechanism}`, RequestBody("PUT", null, null));
- const res = await getResponseMetadata(result);
- return res;
+export async function changeSignupMechanism(
+ org_id: any,
+ signup_mechanism: string
+) {
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}/signup_mechanism?signup_mechanism=${signup_mechanism}`,
+ RequestBody('PUT', null, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
}
export async function validateInviteCode(org_id: any, invite_code: string) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}/invites/code/${invite_code}`, RequestBody("GET", null, null));
- const res = await getResponseMetadata(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}/invites/code/${invite_code}`,
+ RequestBody('GET', null, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
}
diff --git a/apps/web/services/organizations/orgs.ts b/apps/web/services/organizations/orgs.ts
index 59a38163..a08e38cf 100644
--- a/apps/web/services/organizations/orgs.ts
+++ b/apps/web/services/organizations/orgs.ts
@@ -1,5 +1,9 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, errorHandling, getResponseMetadata } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import {
+ RequestBody,
+ errorHandling,
+ getResponseMetadata,
+} from '@services/utils/ts/requests'
/*
This file includes only POST, PUT, DELETE requests
@@ -7,57 +11,85 @@ import { RequestBody, errorHandling, getResponseMetadata } from "@services/utils
*/
export async function createNewOrganization(body: any) {
- const result = await fetch(`${getAPIUrl()}orgs/`, RequestBody("POST", body, null));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}orgs/`,
+ RequestBody('POST', body, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function deleteOrganizationFromBackend(org_id: any) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}`, RequestBody("DELETE", null, null));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function getOrganizationContextInfo(org_slug: any, next: any) {
- const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null, next));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}orgs/slug/${org_slug}`,
+ RequestBody('GET', null, next)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function getOrganizationContextInfoWithId(org_id: any, next: any) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}`, RequestBody("GET", null, next));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}`,
+ RequestBody('GET', null, next)
+ )
+ const res = await errorHandling(result)
+ return res
}
-export async function getOrganizationContextInfoWithoutCredentials(org_slug: any, next: any) {
- let HeadersConfig = new Headers({ "Content-Type": "application/json" });
+export async function getOrganizationContextInfoWithoutCredentials(
+ org_slug: any,
+ next: any
+) {
+ let HeadersConfig = new Headers({ 'Content-Type': 'application/json' })
let options: any = {
- method: "GET",
+ method: 'GET',
headers: HeadersConfig,
- redirect: "follow",
+ redirect: 'follow',
// Next.js
next: next,
- };
+ }
- const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, options);
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, options)
+ const res = await errorHandling(result)
+ return res
}
export function getOrganizationContextInfoNoAsync(org_slug: any, next: any) {
- const result = fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null, next));
- return result;
+ const result = fetch(
+ `${getAPIUrl()}orgs/slug/${org_slug}`,
+ RequestBody('GET', null, next)
+ )
+ return result
}
-export async function updateUserRole(org_id: any, user_id: any, role_uuid: any) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}/users/${user_id}/role/${role_uuid}`, RequestBody("PUT", null, null));
- const res = await getResponseMetadata(result);
- return res;
+export async function updateUserRole(
+ org_id: any,
+ user_id: any,
+ role_uuid: any
+) {
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}/users/${user_id}/role/${role_uuid}`,
+ RequestBody('PUT', null, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
}
export async function removeUserFromOrg(org_id: any, user_id: any) {
- const result = await fetch(`${getAPIUrl()}orgs/${org_id}/users/${user_id}`, RequestBody("DELETE", null, null));
- const res = await getResponseMetadata(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}orgs/${org_id}/users/${user_id}`,
+ RequestBody('DELETE', null, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
}
diff --git a/apps/web/services/settings/org.ts b/apps/web/services/settings/org.ts
index 3007f8a7..7aaedb5c 100644
--- a/apps/web/services/settings/org.ts
+++ b/apps/web/services/settings/org.ts
@@ -1,5 +1,9 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, errorHandling, RequestBodyForm } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import {
+ RequestBody,
+ errorHandling,
+ RequestBodyForm,
+} from '@services/utils/ts/requests'
/*
This file includes only POST, PUT, DELETE requests
@@ -7,16 +11,22 @@ import { RequestBody, errorHandling, RequestBodyForm } from "@services/utils/ts/
*/
export async function updateOrganization(org_id: string, data: any) {
- const result: any = await fetch(`${getAPIUrl()}orgs/` + org_id, RequestBody("PUT", data, null));
- const res = await errorHandling(result);
- return res;
+ const result: any = await fetch(
+ `${getAPIUrl()}orgs/` + org_id,
+ RequestBody('PUT', data, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function uploadOrganizationLogo(org_id: string, logo_file: any) {
// Send file thumbnail as form data
- const formData = new FormData();
- formData.append("logo_file", logo_file);
- const result: any = await fetch(`${getAPIUrl()}orgs/` + org_id + "/logo", RequestBodyForm("PUT", formData, null));
- const res = await errorHandling(result);
- return res;
-}
\ No newline at end of file
+ const formData = new FormData()
+ formData.append('logo_file', logo_file)
+ const result: any = await fetch(
+ `${getAPIUrl()}orgs/` + org_id + '/logo',
+ RequestBodyForm('PUT', formData, null)
+ )
+ const res = await errorHandling(result)
+ return res
+}
diff --git a/apps/web/services/settings/password.ts b/apps/web/services/settings/password.ts
index 86d4a659..8d2ba273 100644
--- a/apps/web/services/settings/password.ts
+++ b/apps/web/services/settings/password.ts
@@ -1,13 +1,16 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, errorHandling } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, errorHandling } from '@services/utils/ts/requests'
/*
This file includes only POST, PUT, DELETE requests
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
*/
-export async function updatePassword(user_id : string, data: any) {
- const result: any = await fetch(`${getAPIUrl()}users/password/user_id/` + user_id, RequestBody("PUT", data, null))
- const res = await errorHandling(result);
- return res;
+export async function updatePassword(user_id: string, data: any) {
+ const result: any = await fetch(
+ `${getAPIUrl()}users/password/user_id/` + user_id,
+ RequestBody('PUT', data, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
diff --git a/apps/web/services/settings/profile.ts b/apps/web/services/settings/profile.ts
index 401d5afe..10fec223 100644
--- a/apps/web/services/settings/profile.ts
+++ b/apps/web/services/settings/profile.ts
@@ -1,13 +1,16 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, errorHandling } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import { RequestBody, errorHandling } from '@services/utils/ts/requests'
/*
This file includes only POST, PUT, DELETE requests
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
*/
-export async function updateProfile(data: any,user_id: number) {
- const result: any = await fetch(`${getAPIUrl()}users/` + user_id, RequestBody("PUT", data, null))
- const res = await errorHandling(result);
- return res;
+export async function updateProfile(data: any, user_id: number) {
+ const result: any = await fetch(
+ `${getAPIUrl()}users/` + user_id,
+ RequestBody('PUT', data, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
diff --git a/apps/web/services/users/users.ts b/apps/web/services/users/users.ts
index b267412b..468ad56c 100644
--- a/apps/web/services/users/users.ts
+++ b/apps/web/services/users/users.ts
@@ -1,16 +1,27 @@
-import { getAPIUrl } from "@services/config/config";
-import { RequestBody, RequestBodyForm, errorHandling, getResponseMetadata } from "@services/utils/ts/requests";
+import { getAPIUrl } from '@services/config/config'
+import {
+ RequestBody,
+ RequestBodyForm,
+ errorHandling,
+ getResponseMetadata,
+} from '@services/utils/ts/requests'
export async function getUser(user_id: string) {
- const result = await fetch(`${getAPIUrl()}users/user_id/${user_id}`, RequestBody("GET", null, null));
- const res = await errorHandling(result);
- return res;
+ const result = await fetch(
+ `${getAPIUrl()}users/user_id/${user_id}`,
+ RequestBody('GET', null, null)
+ )
+ const res = await errorHandling(result)
+ return res
}
export async function updateUserAvatar(user_uuid: any, avatar_file: any) {
- const formData = new FormData();
- formData.append("avatar_file", avatar_file);
- const result: any = await fetch(`${getAPIUrl()}users/update_avatar/${user_uuid}`, RequestBodyForm("PUT", formData, null));
- const res = await getResponseMetadata(result);
- return res;
-}
\ No newline at end of file
+ const formData = new FormData()
+ formData.append('avatar_file', avatar_file)
+ const result: any = await fetch(
+ `${getAPIUrl()}users/update_avatar/${user_uuid}`,
+ RequestBodyForm('PUT', formData, null)
+ )
+ const res = await getResponseMetadata(result)
+ return res
+}
diff --git a/apps/web/services/utils/react/middlewares/views.ts b/apps/web/services/utils/react/middlewares/views.ts
index 1baaa64a..2c8e0c8b 100644
--- a/apps/web/services/utils/react/middlewares/views.ts
+++ b/apps/web/services/utils/react/middlewares/views.ts
@@ -1,12 +1,12 @@
-import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
+import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime'
export const denyAccessToUser = (error: any, router: AppRouterInstance) => {
if (error.status === 401) {
- router.push("/login");
+ router.push('/login')
}
if (error.status === 403) {
- router.push("/login");
+ router.push('/login')
// TODO : add a message to the user to tell him he is not allowed to access this page, route to /error
}
-};
+}
diff --git a/apps/web/services/utils/ts/requests.ts b/apps/web/services/utils/ts/requests.ts
index 21455572..2947964a 100644
--- a/apps/web/services/utils/ts/requests.ts
+++ b/apps/web/services/utils/ts/requests.ts
@@ -1,100 +1,120 @@
-import { getUriWithOrg } from "@services/config/config";
+import { getUriWithOrg } from '@services/config/config'
export const RequestBody = (method: string, data: any, next: any) => {
- let HeadersConfig = new Headers({ "Content-Type": "application/json" });
+ let HeadersConfig = new Headers({ 'Content-Type': 'application/json' })
let options: any = {
method: method,
headers: HeadersConfig,
- redirect: "follow",
- credentials: "include",
+ redirect: 'follow',
+ credentials: 'include',
// Next.js
next: next,
- };
- if (data) {
- options.body = JSON.stringify(data);
}
- return options;
-};
+ if (data) {
+ options.body = JSON.stringify(data)
+ }
+ return options
+}
-export const RequestBodyWithAuthHeader = (method: string, data: any, next: any, token: string) => {
- let HeadersConfig = new Headers(token ? { "Content-Type": "application/json", Authorization: `Bearer ${token}` } : { "Content-Type": "application/json" });
+export const RequestBodyWithAuthHeader = (
+ method: string,
+ data: any,
+ next: any,
+ token: string
+) => {
+ let HeadersConfig = new Headers(
+ token
+ ? { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }
+ : { 'Content-Type': 'application/json' }
+ )
let options: any = {
method: method,
headers: HeadersConfig,
- redirect: "follow",
- credentials: "include",
+ redirect: 'follow',
+ credentials: 'include',
body: data,
// Next.js
next: next,
- };
- return options;
-};
+ }
+ return options
+}
export const RequestBodyForm = (method: string, data: any, next: any) => {
- let HeadersConfig = new Headers({});
+ let HeadersConfig = new Headers({})
let options: any = {
method: method,
headers: HeadersConfig,
- redirect: "follow",
- credentials: "include",
+ redirect: 'follow',
+ credentials: 'include',
body: data,
// Next.js
next: next,
- };
- return options;
-};
+ }
+ return options
+}
export const swrFetcher = async (url: string) => {
// Create the request options
- let HeadersConfig = new Headers({ "Content-Type": "application/json" });
+ let HeadersConfig = new Headers({ 'Content-Type': 'application/json' })
let options: any = {
- method: "GET",
+ method: 'GET',
headers: HeadersConfig,
- redirect: "follow",
- credentials: "include",
- };
+ redirect: 'follow',
+ credentials: 'include',
+ }
try {
// Fetch the data
- const request = await fetch(url, options);
- let res = errorHandling(request);
+ const request = await fetch(url, options)
+ let res = errorHandling(request)
// Return the data
- return res;
+ return res
} catch (error: any) {
- throw error;
+ throw error
}
-};
+}
export const errorHandling = (res: any) => {
if (!res.ok) {
- const error: any = new Error(`${res.statusText}`);
- error.status = res.status;
- throw error;
+ const error: any = new Error(`${res.statusText}`)
+ error.status = res.status
+ throw error
}
- return res.json();
-};
-
+ return res.json()
+}
type CustomResponseTyping = {
- success: boolean;
- data: any;
- status: number;
- HTTPmessage: string;
-};
+ success: boolean
+ data: any
+ status: number
+ HTTPmessage: string
+}
-export const getResponseMetadata = async (fetch_result: any): Promise => {
- const json = await fetch_result.json();
+export const getResponseMetadata = async (
+ fetch_result: any
+): Promise => {
+ const json = await fetch_result.json()
if (fetch_result.status === 200) {
- return { success: true, data: json, status: fetch_result.status, HTTPmessage: fetch_result.statusText };
+ return {
+ success: true,
+ data: json,
+ status: fetch_result.status,
+ HTTPmessage: fetch_result.statusText,
+ }
} else {
- return { success: false, data: json, status: fetch_result.status, HTTPmessage: fetch_result.statusText };
+ return {
+ success: false,
+ data: json,
+ status: fetch_result.status,
+ HTTPmessage: fetch_result.statusText,
+ }
}
-};
+}
export const revalidateTags = async (tags: string[], orgslug: string) => {
- const url = getUriWithOrg(orgslug, "");
+ const url = getUriWithOrg(orgslug, '')
tags.forEach((tag) => {
- fetch(`${url}/api/revalidate?tag=${tag}`);
- });
-};
+ fetch(`${url}/api/revalidate?tag=${tag}`)
+ })
+}