mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: use session access_tokens
This commit is contained in:
parent
08cc97f557
commit
52f2235942
74 changed files with 413 additions and 440 deletions
|
|
@ -52,17 +52,17 @@ const EditActivity = async (params: any) => {
|
|||
const org = await getOrganizationContextInfoWithId(courseInfo.org_id, {
|
||||
revalidate: 180,
|
||||
tags: ['organizations'],
|
||||
})
|
||||
}, access_token)
|
||||
|
||||
return (
|
||||
<EditorOptionsProvider options={{ isEditable: true }}>
|
||||
<AIEditorProvider>
|
||||
<EditorWrapper
|
||||
org={org}
|
||||
course={courseInfo}
|
||||
activity={activity}
|
||||
content={activity.content}
|
||||
></EditorWrapper>
|
||||
<EditorWrapper
|
||||
org={org}
|
||||
course={courseInfo}
|
||||
activity={activity}
|
||||
content={activity.content}
|
||||
></EditorWrapper>
|
||||
</AIEditorProvider>
|
||||
</EditorOptionsProvider>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
'use client'
|
||||
import React from 'react'
|
||||
import { createNewOrganization } from '../../../services/organizations/orgs'
|
||||
|
||||
const Organizations = () => {
|
||||
const [name, setName] = React.useState('')
|
||||
const [description, setDescription] = React.useState('')
|
||||
const [email, setEmail] = React.useState('')
|
||||
const [slug, setSlug] = React.useState('')
|
||||
|
||||
const handleNameChange = (e: any) => {
|
||||
setName(e.target.value)
|
||||
}
|
||||
|
||||
const handleDescriptionChange = (e: any) => {
|
||||
setDescription(e.target.value)
|
||||
}
|
||||
|
||||
const handleEmailChange = (e: any) => {
|
||||
setEmail(e.target.value)
|
||||
}
|
||||
|
||||
const handleSlugChange = (e: any) => {
|
||||
setSlug(e.target.value)
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: any) => {
|
||||
e.preventDefault()
|
||||
|
||||
let logo = ''
|
||||
const status = await createNewOrganization({
|
||||
name,
|
||||
description,
|
||||
email,
|
||||
logo,
|
||||
slug,
|
||||
default: false,
|
||||
})
|
||||
alert(JSON.stringify(status))
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="font-bold text-lg">New Organization</div>
|
||||
Name: <input onChange={handleNameChange} type="text" />
|
||||
<br />
|
||||
Description: <input onChange={handleDescriptionChange} type="text" />
|
||||
<br />
|
||||
Slug: <input onChange={handleSlugChange} type="text" />
|
||||
<br />
|
||||
Email Address: <input onChange={handleEmailChange} type="text" />
|
||||
<br />
|
||||
<button onClick={handleSubmit}>Create</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Organizations
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
'use client' //todo: use server components
|
||||
import Link from 'next/link'
|
||||
import React from 'react'
|
||||
import { deleteOrganizationFromBackend } from '@services/organizations/orgs'
|
||||
import useSWR, { mutate } from 'swr'
|
||||
import { swrFetcher } from '@services/utils/ts/requests'
|
||||
import { getAPIUrl, getUriWithOrg } from '@services/config/config'
|
||||
|
||||
const Organizations = () => {
|
||||
const { data: organizations, error } = useSWR(
|
||||
`${getAPIUrl()}orgs/user/page/1/limit/10`,
|
||||
swrFetcher
|
||||
)
|
||||
|
||||
async function deleteOrganization(org_id: any) {
|
||||
const response = await deleteOrganizationFromBackend(org_id)
|
||||
response &&
|
||||
mutate(
|
||||
`${getAPIUrl()}orgs/user/page/1/limit/10`,
|
||||
organizations.filter((org: any) => org.org_id !== org_id)
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="font-bold text-lg">
|
||||
Your Organizations{' '}
|
||||
<Link href="/organizations/new">
|
||||
<button className="bg-blue-500 text-white px-2 py-1 rounded-md hover:bg-blue-600 focus:outline-none">
|
||||
+
|
||||
</button>
|
||||
</Link>
|
||||
</div>
|
||||
<hr />
|
||||
|
||||
{error && <p className="text-red-500">Failed to load</p>}
|
||||
{!organizations ? (
|
||||
<p className="text-gray-500">Loading...</p>
|
||||
) : (
|
||||
<div>
|
||||
{organizations.map((org: any) => (
|
||||
<div
|
||||
key={org.org_id}
|
||||
className="flex items-center justify-between mb-4"
|
||||
>
|
||||
<Link href={getUriWithOrg(org.slug, '/')}>
|
||||
<h3 className="text-blue-500 cursor-pointer hover:underline">
|
||||
{org.name}
|
||||
</h3>
|
||||
</Link>
|
||||
<button
|
||||
onClick={() => deleteOrganization(org.org_id)}
|
||||
className="px-3 py-1 text-white bg-red-500 rounded-md hover:bg-red-600 focus:outline-none"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Organizations
|
||||
|
|
@ -6,7 +6,6 @@ import { getOrganizationContextInfo } from '@services/organizations/orgs'
|
|||
import { nextAuthOptions } from 'app/auth/options'
|
||||
import { Metadata } from 'next'
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { cookies } from 'next/headers'
|
||||
import Link from 'next/link'
|
||||
|
||||
type MetadataProps = {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ import GeneralWrapperStyled from '@components/StyledElements/Wrappers/GeneralWra
|
|||
import { getUriWithOrg } from '@services/config/config'
|
||||
import { getOrganizationContextInfo } from '@services/organizations/orgs'
|
||||
import { Metadata } from 'next'
|
||||
import { cookies } from 'next/headers'
|
||||
import Link from 'next/link'
|
||||
import { getAccessTokenFromRefreshTokenCookie } from '@services/auth/auth'
|
||||
import CollectionThumbnail from '@components/Objects/Thumbnails/CollectionThumbnail'
|
||||
import NewCollectionButton from '@components/StyledElements/Buttons/NewCollectionButton'
|
||||
import ContentPlaceHolderIfUserIsNotAdmin from '@components/ContentPlaceHolder'
|
||||
|
|
|
|||
|
|
@ -147,8 +147,7 @@ export function MarkStatus(props: {
|
|||
orgslug: string
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const session = useLHSession()
|
||||
console.log(props.course.trail)
|
||||
const session = useLHSession() as any;
|
||||
|
||||
async function markActivityAsCompleteFront() {
|
||||
const trail = await markActivityAsComplete(
|
||||
|
|
@ -171,8 +170,6 @@ export function MarkStatus(props: {
|
|||
}
|
||||
}
|
||||
|
||||
console.log('isActivityCompleted', isActivityCompleted())
|
||||
|
||||
return (
|
||||
<>
|
||||
{isActivityCompleted() ? (
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import { getActivityWithAuthHeader } from '@services/courses/activities'
|
||||
import { getCourseMetadata } from '@services/courses/courses'
|
||||
import { cookies } from 'next/headers'
|
||||
import ActivityClient from './activity'
|
||||
import { getOrganizationContextInfo } from '@services/organizations/orgs'
|
||||
import { Metadata } from 'next'
|
||||
import { getAccessTokenFromRefreshTokenCookie } from '@services/auth/auth'
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { nextAuthOptions } from 'app/auth/options'
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import { useLHSession } from '@components/Contexts/LHSessionContext'
|
|||
const CourseClient = (props: any) => {
|
||||
const [user, setUser] = useState<any>({})
|
||||
const [learnings, setLearnings] = useState<any>([])
|
||||
const session = useLHSession()
|
||||
const session = useLHSession() as any;
|
||||
const courseuuid = props.courseuuid
|
||||
const orgslug = props.orgslug
|
||||
const course = props.course
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import React from 'react'
|
||||
import CourseClient from './course'
|
||||
import { cookies } from 'next/headers'
|
||||
import { getCourseMetadata } from '@services/courses/courses'
|
||||
import { getOrganizationContextInfo } from '@services/organizations/orgs'
|
||||
import { Metadata } from 'next'
|
||||
import { getAccessTokenFromRefreshTokenCookie } from '@services/auth/auth'
|
||||
import { getCourseThumbnailMediaDirectory } from '@services/media/media'
|
||||
import { nextAuthOptions } from 'app/auth/options'
|
||||
import { getServerSession } from 'next-auth'
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ import React from 'react'
|
|||
import Courses from './courses'
|
||||
import { Metadata } from 'next'
|
||||
import { getOrganizationContextInfo } from '@services/organizations/orgs'
|
||||
import { cookies } from 'next/headers'
|
||||
import { getAccessTokenFromRefreshTokenCookie } from '@services/auth/auth'
|
||||
import { nextAuthOptions } from 'app/auth/options'
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { getOrgCourses } from '@services/courses/courses'
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import React from 'react'
|
|||
import { Metadata } from 'next'
|
||||
import { getOrganizationContextInfo } from '@services/organizations/orgs'
|
||||
import Trail from './trail'
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { nextAuthOptions } from 'app/auth/options'
|
||||
|
||||
type MetadataProps = {
|
||||
params: { orgslug: string }
|
||||
|
|
@ -11,11 +13,13 @@ type MetadataProps = {
|
|||
export async function generateMetadata({
|
||||
params,
|
||||
}: MetadataProps): Promise<Metadata> {
|
||||
const session = await getServerSession(nextAuthOptions)
|
||||
const access_token = session?.tokens?.access_token
|
||||
// Get Org context information
|
||||
const org = await getOrganizationContextInfo(params.orgslug, {
|
||||
revalidate: 1800,
|
||||
tags: ['organizations'],
|
||||
})
|
||||
}, access_token)
|
||||
return {
|
||||
title: 'Trail — ' + org.name,
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use client'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||
import { useOrg } from '@components/Contexts/OrgContext'
|
||||
import PageLoading from '@components/Objects/Loaders/PageLoading'
|
||||
import TrailCourseElement from '@components/Pages/Trail/TrailCourseElement'
|
||||
|
|
@ -11,14 +12,16 @@ import useSWR from 'swr'
|
|||
|
||||
function Trail(params: any) {
|
||||
let orgslug = params.orgslug
|
||||
const session = useLHSession() as any
|
||||
const access_token = session.data.tokens.access_token;
|
||||
const org = useOrg() as any
|
||||
const orgID = org?.id
|
||||
const { data: trail, error: error } = useSWR(
|
||||
`${getAPIUrl()}trail/org/${orgID}/trail`,
|
||||
swrFetcher
|
||||
(url) => swrFetcher(url, access_token)
|
||||
)
|
||||
|
||||
useEffect(() => {}, [trail, org])
|
||||
useEffect(() => { }, [trail, org])
|
||||
|
||||
return (
|
||||
<GeneralWrapperStyled>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import Link from 'next/link'
|
|||
import { CourseOverviewTop } from '@components/Dashboard/UI/CourseOverviewTop'
|
||||
import { motion } from 'framer-motion'
|
||||
import EditCourseGeneral from '@components/Dashboard/Course/EditCourseGeneral/EditCourseGeneral'
|
||||
import { GalleryVerticalEnd, Info, Lock, UserRoundCog } from 'lucide-react'
|
||||
import { GalleryVerticalEnd, Info, UserRoundCog } from 'lucide-react'
|
||||
import EditCourseAccess from '@components/Dashboard/Course/EditCourseAccess/EditCourseAccess'
|
||||
|
||||
export type CourseOverviewParams = {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
import LeftMenu from '@components/Dashboard/UI/LeftMenu'
|
||||
import AdminAuthorization from '@components/Security/AdminAuthorization'
|
||||
import ClientComponentSkeleton from '@components/Utils/ClientComp'
|
||||
import { Metadata } from 'next'
|
||||
import { SessionProvider } from 'next-auth/react'
|
||||
import React from 'react'
|
||||
import ClientAdminLayout from './ClientAdminLayout'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
'use client'
|
||||
import LHSessionProvider from '@components/Contexts/LHSessionContext'
|
||||
import { OrgProvider } from '@components/Contexts/OrgContext'
|
||||
import Toast from '@components/StyledElements/Toast/Toast'
|
||||
import '@styles/globals.css'
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import React from 'react'
|
|||
import { AlertTriangle } from 'lucide-react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { signIn, useSession } from "next-auth/react"
|
||||
import { signIn } from "next-auth/react"
|
||||
import { getUriWithOrg } from '@services/config/config'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ const validate = (values: any) => {
|
|||
const LoginClient = (props: LoginClientProps) => {
|
||||
const [isSubmitting, setIsSubmitting] = React.useState(false)
|
||||
const router = useRouter();
|
||||
const session = useLHSession();
|
||||
const session = useLHSession() as any;
|
||||
|
||||
const [error, setError] = React.useState('')
|
||||
const formik = useFormik({
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import { getUriWithOrg } from '@services/config/config'
|
|||
import { useOrg } from '@components/Contexts/OrgContext'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { useFormik } from 'formik'
|
||||
import { resetPassword, sendResetLink } from '@services/auth/auth'
|
||||
import { resetPassword } from '@services/auth/auth'
|
||||
|
||||
const validate = (values: any) => {
|
||||
const errors: any = {}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import Link from 'next/link'
|
|||
import { getUriWithOrg } from '@services/config/config'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||
import React, { useEffect } from 'react'
|
||||
import { MailWarning, Shield, Ticket, UserPlus } from 'lucide-react'
|
||||
import { MailWarning, Ticket, UserPlus } from 'lucide-react'
|
||||
import { useOrg } from '@components/Contexts/OrgContext'
|
||||
import UserAvatar from '@components/Objects/UserAvatar'
|
||||
import OpenSignUpComponent from './OpenSignup'
|
||||
|
|
@ -33,9 +33,6 @@ function SignUpClient(props: SignUpClientProps) {
|
|||
setJoinMethod(
|
||||
props.org?.config?.config?.GeneralConfig.users.signup_mechanism
|
||||
)
|
||||
console.log(
|
||||
props.org?.config?.config?.GeneralConfig.users.signup_mechanism
|
||||
)
|
||||
}
|
||||
if (inviteCodeParam) {
|
||||
setInviteCode(inviteCodeParam)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue