Skip to content

Commit

Permalink
Merge pull request #298 from universi-me/main
Browse files Browse the repository at this point in the history
Atualizando branch
  • Loading branch information
710lucas authored Dec 6, 2023
2 parents a01e917 + b7b9471 commit 7ddf446
Show file tree
Hide file tree
Showing 37 changed files with 1,689 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext, useMemo, useState } from "react";
import { Link, redirect } from "react-router-dom";
import { Link, redirect, useNavigate } from "react-router-dom";
import { ProfileImage } from "@/components/ProfileImage/ProfileImage";
import { AuthContext } from "@/contexts/Auth";
import "./WelcomeUser.less"
Expand All @@ -8,6 +8,7 @@ import * as DropdownMenu from "@radix-ui/react-dropdown-menu"

export function WelcomeUser() {
const auth = useContext(AuthContext);
const navigate = useNavigate();

const [profileClicked, setProfileClicked] = useState(false)

Expand All @@ -24,10 +25,13 @@ export function WelcomeUser() {
profileClicked
?
<div className="submenu-profile">
<div className="submenu-item" onClick={()=>{location.href="/profile/"+auth.profile?.user.name}}>
<div className="submenu-item" onClick={()=>{navigate("/profile/"+auth.profile?.user.name); setProfileClicked(false)}}>
Perfil
</div>
<div className="submenu-item" onClick={()=>{auth.signout()}}>
{ auth.user?.accessLevel === "ROLE_ADMIN" && <div className="submenu-item" onClick={() => {navigate("/settings"); setProfileClicked(false)}}>
Configurações
</div> }
<div className="submenu-item" onClick={()=>{auth.signout(); setProfileClicked(false)}}>
Sair
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/Auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
if (profile)
updateOrganization();
else
setOrganization(null);
updateOrganization();
//setOrganization(null);

setFinishedLogin(true);
return profile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function GroupContentMaterials() {
groupContext.setEditMaterial(data);
},
hidden() {
return groupContext?.group.admin.id !== groupContext?.loggedData.profile.id;
return !groupContext?.group.canEdit;
},
},
{
Expand All @@ -47,7 +47,7 @@ export function GroupContentMaterials() {
className: "delete",
onSelect: handleDeleteMaterial,
hidden() {
return groupContext?.group.admin.id !== groupContext?.loggedData.profile.id;
return !groupContext?.group.canEdit;
},
}
];
Expand All @@ -59,10 +59,8 @@ export function GroupContentMaterials() {
<div className="go-right">
<Filter setter={setFilterMaterials} placeholderMessage={`Buscar em ${groupContext.group.name}`}/>
{
groupContext.loggedData.profile.id == groupContext.group.admin.id || groupContext.loggedData.profile?.id == groupContext.group.organization?.admin.id ?
groupContext.group.canEdit &&
<ActionButton name="Criar material" buttonProps={{onClick(){groupContext.setEditMaterial(null)}}}/>
:
<></>
}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function GroupContents() {
groupContext.setEditContent(data);
},
hidden() {
return groupContext?.group.admin.id !== groupContext?.loggedData.profile.id;
return !groupContext?.group.canEdit;
},
},
{
Expand All @@ -42,7 +42,7 @@ export function GroupContents() {
className: "delete",
onSelect: handleDeleteContent,
hidden() {
return groupContext?.group.admin.id !== groupContext?.loggedData.profile.id;
return !groupContext?.group.canEdit;
},
}
]
Expand All @@ -53,12 +53,10 @@ export function GroupContents() {
<div className="go-right">
<Filter setter={setFilterContents} placeholderMessage={`Buscar em Conteúdos ${groupContext.group.name}`}/>
{
authContext.profile?.id == groupContext.group.admin.id || authContext.profile?.id == groupContext.group.organization?.admin.id ?
groupContext.group.canEdit &&
<ActionButton name="Criar conteúdo" buttonProps={{
onClick(){ groupContext.setEditContent(null); }
}} />
:
<></>
}
</div>
</div>
Expand Down
27 changes: 20 additions & 7 deletions src/pages/ManageProfile/ManageProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,39 @@ export function ManageProfilePage() {
}
}

const { value: password, isConfirmed } = await SwalUtils.fireModal({
title: "Edição de perfil",
input: "password",
inputLabel: "Inserir senha para salvar as alterações",
inputPlaceholder: "Insira sua senha",
confirmButtonText: "Confirmar Alterações",
showCancelButton: true,
cancelButtonText: "Cancelar",
allowOutsideClick: true,
showCloseButton: true,
inputAttributes: {
autocapitalize: "off",
autocorrect: "off"
}
});
if (!isConfirmed)
return;

UniversimeApi.Profile.edit({
profileId: profile.id,
name: firstname,
lastname,
bio,
gender: gender || undefined,
imageUrl: newImageUrl,
rawPassword: password,
}).then(async res => {
if (!res.success)
throw new Error(res.message);

const p = await authContext.updateLoggedUser();
navigate(`/profile/${p!.user.name}`);
}).catch((reason: Error) => {
SwalUtils.fireModal({
title: "Erro ao salvar alterações de perfil",
text: reason.message,
icon: 'error',
});
})
})
}

function submitLinkChanges(e: MouseEvent<HTMLButtonElement>) {
Expand Down
10 changes: 7 additions & 3 deletions src/pages/Recovery/Recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import "./Recovery.css"
import { transform } from "@babel/core"
import { Translate } from "phosphor-react"
import "../singin/signinForm.css"
import {useState} from "react"
import {useState, useContext} from "react"
import UniversimeApi from "@/services/UniversimeApi"
import { AuthContext } from "@/contexts/Auth/AuthContext";
import * as SwalUtils from "@/utils/sweetalertUtils"
import ReCAPTCHA from "react-google-recaptcha-enterprise";

export default function Recovery(){
const auth = useContext(AuthContext);

const [username, setUsername] = useState("")
const [msg, setMsg] = useState<null | string>(null)
Expand All @@ -31,7 +33,9 @@ export default function Recovery(){
})
}

const ENABLE_RECAPTCHA = import.meta.env.VITE_ENABLE_RECAPTCHA === "true" || import.meta.env.VITE_ENABLE_RECAPTCHA === "1";
const organizationEnv = (((auth.organization??{} as any).groupSettings??{} as any).environment??{} as any);
const ENABLE_RECAPTCHA = organizationEnv.recaptcha_enabled ?? (import.meta.env.VITE_ENABLE_RECAPTCHA === "true" || import.meta.env.VITE_ENABLE_RECAPTCHA === "1");
const RECAPTCHA_SITE_KEY = organizationEnv.recaptcha_site_key ?? import.meta.env.VITE_RECAPTCHA_SITE_KEY;

return(
<div>
Expand All @@ -57,7 +61,7 @@ export default function Recovery(){
!ENABLE_RECAPTCHA ? null :
<center>
<br/>
<ReCAPTCHA ref={(r) => setRecaptchaRef(r) } sitekey={import.meta.env.VITE_RECAPTCHA_SITE_KEY} onChange={handleRecaptchaChange} />
<ReCAPTCHA ref={(r) => setRecaptchaRef(r) } sitekey={RECAPTCHA_SITE_KEY} onChange={handleRecaptchaChange} />
<br/>
</center>
}
Expand Down
15 changes: 15 additions & 0 deletions src/pages/Settings/EnvironmentsPage/EnvironmentsLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { type LoaderFunctionArgs } from "react-router-dom";
import UniversimeApi from "@/services/UniversimeApi";

export type EnvironmentsLoaderResponse = {
envDic: {} | undefined;
};

export async function EnvironmentsFetch(): Promise<EnvironmentsLoaderResponse> {
const environments = await UniversimeApi.Group.listEnvironments({});
return { envDic: (environments as any).body.environments??{}, };
}

export async function EnvironmentsLoader(args: LoaderFunctionArgs) {
return EnvironmentsFetch();
}
183 changes: 183 additions & 0 deletions src/pages/Settings/EnvironmentsPage/EnvironmentsPage.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
@import url(/src/layouts/colors.less);
@import url(/src/layouts/fonts.less);
@import url(/src/layouts/transitions.less);
@import url(/src/layouts/border-radius.less);

#environments-settings {

.environments-list {
margin-top: 1rem;

.environments-item {

margin: .5rem;
align-items: center;

h3 {
margin-top: 1.5rem;
margin-bottom: 1rem;
font-size: 1.2rem;
margin-left: 1rem;
align-items: center;
}

.environments-label {
display: flex;
font-size: 1rem;
margin-bottom: .5rem;
margin-left: 0;
text-align: left;
align-items: center;
}

&:not(:last-of-type) {
@margin-size: .75rem;

padding-bottom: @margin-size;
margin-bottom: @margin-size;
border-bottom: solid 1px @card-item-color;
}

.enabled-delete-wrapper {

margin-bottom: .5rem;
display: flex;
justify-content: space-between;
margin-left: 2rem;
align-items: center;

&:not(:last-of-type) {
@margin-size: .5rem;

padding-bottom: @margin-size;
margin-bottom: @margin-size;
border-bottom: solid 1px @card-item-color;
}

.enabled-wrapper {
display: flex;
align-items: center;

.filter-enabled-root {



@radix-switch-width: 2.5rem;
@radix-switch-height: 1.5rem;
@radix-thumb-diameter: @radix-switch-height;

width: @radix-switch-width;
height: @radix-switch-height;
margin-right: .5rem;
margin-left: .5rem;

border-radius: 9999px;
border: none;
outline: 2px solid @primary-color;

box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);

cursor: pointer;

&:focus {
outline: 2px solid @secondary-color;
}

&:not([data-state='checked']) {
background-color: @card-background-color;
}

&[data-state='checked'] {
background-color: @card-item-color;

.filter-enabled-thumb {
transform: translateX(calc(@radix-switch-width - @radix-thumb-diameter));
background-color: @primary-color;
}
}

.filter-enabled-thumb {
display: block;
width: @radix-thumb-diameter;
height: @radix-thumb-diameter;
background-color: #FFF;
border-radius: 50%;
outline: 2px solid @primary-color;

transition: transform 100ms;
will-change: transform;
}

}

}



.environments-text-wrapper {
@email-font-size: 1rem;
@email-padding: .5rem;
@trigger-width: 9.25em;

display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;

align-items: center;

.environments-text-input {

align-items: center;
font-size: @email-font-size;
padding: @email-padding;

background-color: @card-item-color;
border: none;
border-radius: .625rem;

width: calc(100% + @trigger-width + 10em);

}
}
}

}
}

.buttons-wrapper {
display: flex;
flex-direction: row;
align-items: center;
justify-content: end;

margin-top: 1rem;
width: 100%;

> button {
padding: .5em 1em;
border: none;

font-size: 1rem;
text-transform: uppercase;
font-weight: @font-weight-bold;

cursor: pointer;

& + button {
margin-left: 1rem;
}

&.submit {
color: @font-color-v1;
background-color: @primary-color;
border-radius: .625rem;

&[disabled] {
background-color: @card-item-color;
color: @font-color-v2;
}
}
}
}
}
Loading

0 comments on commit 7ddf446

Please sign in to comment.