fix: signup remaining bugs

This commit is contained in:
swve 2024-01-25 23:49:29 +01:00
parent 0d775a0fe9
commit fdd21c2eda
4 changed files with 57 additions and 51 deletions

View file

@ -240,12 +240,14 @@ async def delete_invite_code(
)
# Delete invite code
invite_code = r.delete(f"{invite_code_uuid}:org:{org.org_uuid}:code:*")
keys = r.keys(f"{invite_code_uuid}:org:{org.org_uuid}:code:*")
if keys:
r.delete(*keys)
if not invite_code:
if not keys:
raise HTTPException(
status_code=404,
detail="Invite code not found",
)
return invite_code
return keys

View file

@ -12,7 +12,7 @@ export async function generateMetadata(
): Promise<Metadata> {
const orgslug = params.orgslug;
// Get Org context information
const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800, tags: ['organizations'] });
const org = await getOrganizationContextInfo(orgslug, { revalidate: 0, tags: ['organizations'] });
return {
title: 'Login' + `${org.name}`,
@ -21,7 +21,7 @@ export async function generateMetadata(
const Login = async (params: any) => {
const orgslug = params.params.orgslug;
const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800, tags: ['organizations'] });
const org = await getOrganizationContextInfo(orgslug, { revalidate: 0, tags: ['organizations'] });
return (
<div>

View file

@ -15,7 +15,7 @@ export async function generateMetadata(
): Promise<Metadata> {
const orgslug = params.orgslug;
// Get Org context information
const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800, tags: ['organizations'] });
const org = await getOrganizationContextInfo(orgslug, { revalidate: 0, tags: ['organizations'] });
return {
title: 'Sign up' + `${org.name}`,
@ -24,7 +24,7 @@ export async function generateMetadata(
const SignUp = async (params: any) => {
const orgslug = params.params.orgslug;
const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800, tags: ['organizations'] });
const org = await getOrganizationContextInfo(orgslug, { revalidate: 0, tags: ['organizations'] });
return (
<>

View file

@ -19,25 +19,25 @@ import toast from "react-hot-toast";
interface SignUpClientProps {
org: any;
}
}
function SignUpClient(props : SignUpClientProps) {
function SignUpClient(props: SignUpClientProps) {
const session = useSession() as any;
const [joinMethod, setJoinMethod] = React.useState('open');
const [inviteCode , setInviteCode] = React.useState('');
const [inviteCode, setInviteCode] = React.useState('');
const searchParams = useSearchParams()
const inviteCodeParam = searchParams.get('inviteCode')
useEffect(() => {
if (props.org.config){
if (props.org.config) {
setJoinMethod(props.org?.config?.config?.GeneralConfig.users.signup_mechanism);
console.log(props.org?.config?.config?.GeneralConfig.users.signup_mechanism)
}
if (inviteCodeParam){
if (inviteCodeParam) {
setInviteCode(inviteCodeParam);
}
}
, [props.org,inviteCodeParam]);
, [props.org, inviteCodeParam]);
return (
<div className='grid grid-flow-col justify-stretch h-screen'>
@ -67,10 +67,14 @@ function SignUpClient(props : SignUpClientProps) {
</div>
</div>
<div className="left-join-part bg-white flex flex-row">
{joinMethod == 'open' && <OpenSignUpComponent />}
{joinMethod == 'inviteOnly' && inviteCode && session.isAuthenticated && <LoggedInJoinScreen />}
{joinMethod == 'inviteOnly' && inviteCode && !session.isAuthenticated && <InviteOnlySignUpComponent inviteCode={inviteCode} />}
{joinMethod == 'inviteOnly' && !inviteCode && <NoTokenScreen />}
{joinMethod == 'open' && (
session.isAuthenticated ? <LoggedInJoinScreen inviteCode={inviteCode} /> : <OpenSignUpComponent />
)}
{joinMethod == 'inviteOnly' && (
inviteCode ? (
session.isAuthenticated ? <LoggedInJoinScreen /> : <InviteOnlySignUpComponent inviteCode={inviteCode} />
) : <NoTokenScreen />
)}
</div>
</div>
)
@ -86,7 +90,7 @@ const LoggedInJoinScreen = (props: any) => {
const [isLoading, setIsLoading] = React.useState(true);
useEffect(() => {
if(session && org){
if (session && org) {
setIsLoading(false);
}
@ -120,7 +124,7 @@ const NoTokenScreen = (props: any) => {
const org = useOrg() as any;
const router = useRouter();
const [isLoading, setIsLoading] = React.useState(true);
const [inviteCode , setInviteCode] = React.useState('');
const [inviteCode, setInviteCode] = React.useState('');
const [messsage, setMessage] = React.useState('bruh');
const handleInviteCodeChange = (e: any) => {
@ -129,7 +133,7 @@ const NoTokenScreen = (props: any) => {
const validateCode = async () => {
setIsLoading(true);
let res = await validateInviteCode(org?.id,inviteCode);
let res = await validateInviteCode(org?.id, inviteCode);
//wait for 1s
if (res.success) {
toast.success("Invite code is valid, you'll be redirected to the signup page in a few seconds");
@ -146,7 +150,7 @@ const NoTokenScreen = (props: any) => {
useEffect(() => {
if(session && org){
if (session && org) {
setIsLoading(false);
}
@ -167,7 +171,7 @@ const NoTokenScreen = (props: any) => {
<Shield size={18} />
<p>Submit </p>
</button>
</div> }
</div>}
</div>
)
}