chore: remove depreceated settings code

This commit is contained in:
swve 2023-12-13 22:04:16 +01:00
parent 55c097a50e
commit 669270441b
10 changed files with 0 additions and 583 deletions

View file

@ -1,30 +0,0 @@
import { getOrganizationContextInfo } from "@services/organizations/orgs";
import { Metadata } from "next";
import PasswordsClient from "./passwords";
type MetadataProps = {
params: { orgslug: string };
searchParams: { [key: string]: string | string[] | undefined };
};
export async function generateMetadata(
{ params }: MetadataProps,
): Promise<Metadata> {
// Get Org context information
const org = await getOrganizationContextInfo(params.orgslug, { revalidate: 1800, tags: ['organizations'] });
return {
title: `Settings: Passwords — ${org.name}`,
description: org.description,
};
}
function SettingsProfilePasswordsPage() {
return (
<>
<PasswordsClient></PasswordsClient>
</>
)
}
export default SettingsProfilePasswordsPage

View file

@ -1,77 +0,0 @@
"use client";
import { AuthContext } from '@components/Security/AuthProviderDepreceated';
import React, { useEffect } from 'react'
import { Formik, Form, Field, ErrorMessage } from 'formik';
import { updatePassword } from '@services/settings/password';
function PasswordsClient() {
const auth: any = React.useContext(AuthContext);
const updatePasswordUI = async (values: any) => {
let user_id = auth.userInfo.user_object.user_id;
await updatePassword(user_id, values)
}
return (
<div>
{auth.isAuthenticated && (
<div>
<h1 className='text-3xl font-bold'>Account Password</h1>
<br /><br />
<Formik
initialValues={{ old_password: '', new_password: '' }}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
setSubmitting(false);
updatePasswordUI(values)
}, 400);
}}
>
{({ isSubmitting }) => (
<Form className="max-w-md">
<label className="block mb-2 font-bold" htmlFor="old_password">
Old Password
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="password"
name="old_password"
/>
<label className="block mb-2 font-bold" htmlFor="new_password">
New Password
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="password"
name="new_password"
/>
<button
type="submit"
disabled={isSubmitting}
className="px-6 py-3 text-white bg-black rounded-lg shadow-md hover:bg-black focus:outline-none focus:ring-2 focus:ring-blue-500"
>
Submit
</button>
</Form>
)}
</Formik>
</div>
)}
</div>
)
}
export default PasswordsClient

View file

@ -1,26 +0,0 @@
import { getOrganizationContextInfo } from "@services/organizations/orgs";
import { Metadata } from "next";
import ProfileClient from "./profile";
type MetadataProps = {
params: { orgslug: string };
searchParams: { [key: string]: string | string[] | undefined };
};
export async function generateMetadata(
{ params }: MetadataProps,
): Promise<Metadata> {
// Get Org context information
const org = await getOrganizationContextInfo(params.orgslug, { revalidate: 1800, tags: ['organizations'] });
return {
title: `Settings: Profile — ${org.name}`,
description: org.description,
};
}
function SettingsProfilePage() {
return <ProfileClient></ProfileClient>
}
export default SettingsProfilePage

View file

@ -1,81 +0,0 @@
"use client";
import { AuthContext } from '@components/Security/AuthProviderDepreceated';
import React, { useEffect } from 'react'
import { Formik, Form, Field, ErrorMessage } from 'formik';
import { updateProfile } from '@services/settings/profile';
function ProfileClient() {
const auth: any = React.useContext(AuthContext);
return (
<div>
{auth.isAuthenticated && (
<div>
<h1 className='text-3xl font-bold'>Profile Settings</h1>
<br /><br />
<Formik
initialValues={auth.userInfo.user_object}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
setSubmitting(false);
updateProfile(values)
}, 400);
}}
>
{({ isSubmitting }) => (
<Form className="max-w-md">
<label className="block mb-2 font-bold" htmlFor="full_name">
Full Name
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="textarea"
name="full_name"
/>
<label className="block mb-2 font-bold" htmlFor="email">
Email
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="email"
name="email"
/>
<label className="block mb-2 font-bold" htmlFor="bio">
Bio
</label>
<Field
as="textarea"
className="w-full h-64 px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="textarea"
name="bio"
/>
<button
type="submit"
disabled={isSubmitting}
className="px-6 py-3 text-white bg-black rounded-lg shadow-md hover:bg-black focus:outline-none focus:ring-2 focus:ring-blue-500"
>
Submit
</button>
</Form>
)}
</Formik>
</div>
)}
</div>
)
}
export default ProfileClient

View file

@ -1,15 +0,0 @@
import { createStitches } from '@stitches/react';
export const { getCssText } = createStitches();
export default function Head() {
return (
<>
<title>Settings</title>
<meta content="width=device-width, initial-scale=1" name="viewport" />
<link rel="icon" href="/favicon.ico" />
<style id="stitches" dangerouslySetInnerHTML={{ __html: getCssText() }} />
</>
)
}

View file

@ -1,128 +0,0 @@
"use client";
import React, { createContext, useState } from 'react'
import { styled } from '@stitches/react';
import Link from 'next/link';
import LearnHouseWhiteLogo from '@public/learnhouse_text_white.png';
import AuthProvider, { AuthContext } from '@components/Security/AuthProviderDepreceated';
import Avvvatars from 'avvvatars-react';
import Image from 'next/image';
import AuthenticatedClientElement from '@components/Security/AuthenticatedClientElement';
import { getOrganizationContextInfo } from '@services/organizations/orgs';
import useSWR, { mutate } from "swr";
import { getAPIUrl } from '@services/config/config';
import { swrFetcher } from '@services/utils/ts/requests';
function SettingsLayout({ children, params }: { children: React.ReactNode, params: any }) {
const auth: any = React.useContext(AuthContext);
const orgslug = params.orgslug;
const { data: org, error: error } = useSWR(`${getAPIUrl()}orgs/slug/${orgslug}`, swrFetcher);
return (
<>
<AuthProvider>
<Main>
<LeftWrapper>
<LeftTopArea>
<Link href={"/"}><Image alt="Learnhouse logo" width={128} src={LearnHouseWhiteLogo} /></Link>
{auth.isAuthenticated && (
<Avvvatars value={auth.userInfo.user_object.user_id} style="shape" />
)}
</LeftTopArea>
<LeftMenuWrapper>
<MenuTitle>Account</MenuTitle>
<ul>
<li><Link href="/settings/account/profile">Profile</Link></li>
<li><Link href="/settings/account/passwords">Passwords</Link></li>
</ul>
<AuthenticatedClientElement
ressourceType='organization'
action='update'
checkMethod='roles' >
<MenuTitle>Organization</MenuTitle>
<ul>
<li><Link href="/settings/organization/general">General</Link></li>
</ul>
</AuthenticatedClientElement>
</LeftMenuWrapper>
</LeftWrapper>
<RightWrapper>
{children}
</RightWrapper>
</Main></AuthProvider>
</>
)
}
export default SettingsLayout
const Main = styled('div', {
display: 'flex',
})
const LeftWrapper = styled('div', {
width: '270px',
background: "linear-gradient(348.55deg, #010101 -8.61%, #343434 105.52%);",
height: '100vh',
padding: '20px',
})
const LeftTopArea = styled('div', {
display: 'flex',
marginLeft: '20px',
alignItems: 'center',
img: {
marginRight: '20px',
},
a: {
display: 'flex',
placeItems: 'center',
placeContent: 'center',
}
})
const LeftMenuWrapper = styled('div', {
display: 'flex',
flexDirection: 'column',
padding: '20px',
ul: {
listStyle: 'none',
padding: 0,
margin: 0,
li: {
marginBottom: '10px',
a: {
color: '#ffffff8c',
textDecoration: 'none',
fontSize: '14px',
fontWeight: 'bold',
'&:hover': {
textDecoration: 'underline',
}
}
}
}
})
const MenuTitle = styled('h3', {
color: 'white',
fontSize: '18px',
fontWeight: 'bold',
marginBottom: '20px',
})
const RightWrapper = styled('div', {
flex: 1,
padding: '20px',
boxSizing: 'border-box',
margin: '40px',
})

View file

@ -1,156 +0,0 @@
"use client";
import React, { useState } from 'react'
import { Field, Form, Formik } from 'formik';
import { updateOrganization, uploadOrganizationLogo } from '@services/settings/org';
import { UploadCloud } from 'lucide-react';
import { revalidateTags } from '@services/utils/ts/requests';
import { useRouter } from 'next/navigation';
interface OrganizationValues {
name: string;
description: string;
slug: string;
logo: string;
email: string;
}
function OrganizationClient(props: any) {
const [selectedFile, setSelectedFile] = useState<File | null>(null);
const router = useRouter();
// ...
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.files && event.target.files.length > 0) {
const file = event.target.files[0];
setSelectedFile(file);
}
};
const uploadLogo = async () => {
if (selectedFile) {
let org_id = org.org_id;
await uploadOrganizationLogo(org_id, selectedFile);
setSelectedFile(null); // Reset the selected file
await revalidateTags(['organizations'], org.slug);
router.refresh();
}
};
const org = props.org;
let orgValues: OrganizationValues = {
name: org.name,
description: org.description,
slug: org.slug,
logo: org.logo,
email: org.email
}
const updateOrg = async (values: OrganizationValues) => {
let org_id = org.org_id;
await updateOrganization(org_id, values);
// Mutate the org
await revalidateTags(['organizations'], org.slug);
router.refresh();
}
return (
<div>
<h1 className='text-3xl font-bold'>Organization Settings</h1>
<br /><br />
<Formik
initialValues={orgValues}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
setSubmitting(false);
updateOrg(values)
}, 400);
}}
>
{({ isSubmitting }) => (
<Form>
<label className="block mb-2 font-bold" htmlFor="name">
Name
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="text"
name="name"
/>
<label className="block mb-2 font-bold" htmlFor="description">
Description
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="text"
name="description"
/>
<label className="block mb-2 font-bold" htmlFor="slug">
Logo
</label>
<div className="flex items-center justify-center w-full ">
<input
className="w-full px-4 py-2 mr-1 border rounded-lg bg-gray-200 cursor-not-allowed"
type="file"
name="logo"
onChange={handleFileChange}
/>
<button
type="button"
onClick={uploadLogo}
disabled={isSubmitting || selectedFile === null}
className="px-6 py-3 text-white bg-gray-500 rounded-lg hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-black"
>
<UploadCloud size={24} />
</button>
</div>
<label className="block mb-2 font-bold" htmlFor="slug">
Slug
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg bg-gray-200 cursor-not-allowed"
disabled
type="text"
name="slug"
/>
<label className="block mb-2 font-bold" htmlFor="email">
Email
</label>
<Field
className="w-full px-4 py-2 mb-4 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
type="email"
name="email"
/>
<button
type="submit"
disabled={isSubmitting}
className="px-6 py-3 text-white bg-black rounded-lg shadow-md hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-black"
>
Submit
</button>
</Form>
)}
</Formik>
</div>
)
}
export default OrganizationClient

View file

@ -1,33 +0,0 @@
import { getOrganizationContextInfo } from '@services/organizations/orgs';
import { Metadata } from 'next';
import OrganizationClient from './organization';
type MetadataProps = {
params: { orgslug: string };
searchParams: { [key: string]: string | string[] | undefined };
};
export async function generateMetadata(
{ params }: MetadataProps,
): Promise<Metadata> {
// Get Org context information
const org = await getOrganizationContextInfo(params.orgslug, { revalidate: 1800, tags: ['organizations'] });
return {
title: `Settings: General — ${org.name}`,
description: org.description,
};
}
async function SettingsOrganizationGeneral(params: any) {
const orgslug = params.params.orgslug;
const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800, tags: ['organizations'] });
return (
<>
<OrganizationClient org={org} />
</>
)
}
export default SettingsOrganizationGeneral

View file

@ -1,9 +0,0 @@
import React from 'react'
function SettingsOrganizationRole() {
return (
<div>SettingsOrganizationRole</div>
)
}
export default SettingsOrganizationRole

View file

@ -1,28 +0,0 @@
import { getOrganizationContextInfo } from "@services/organizations/orgs";
import { Metadata, ResolvingMetadata } from 'next';
type MetadataProps = {
params: { orgslug: string };
searchParams: { [key: string]: string | string[] | undefined };
};
export async function generateMetadata(
{ params }: MetadataProps,
): Promise<Metadata> {
// Get Org context information
const org = await getOrganizationContextInfo(params.orgslug, { revalidate: 1800, tags: ['organizations'] });
return {
title: `Settings — ${org.name}`,
description: org.description,
};
}
function Settings() {
return (
<div>Settings</div>
)
}
export default Settings