Skip to content

Commit

Permalink
change: adjust organization logo in header
Browse files Browse the repository at this point in the history
  • Loading branch information
julio-ufpb committed Dec 29, 2023
1 parent a4acc66 commit 33bb71a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
33 changes: 17 additions & 16 deletions src/components/UniversiHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import { Link } from "react-router-dom";
import { WelcomeUser } from "./components/WelcomeUser/WelcomeUser";
import { LoginButton } from "./components/LoginButton/LoginButton";
import { useContext, createRef } from "react";
import { AuthContext } from "@/contexts/Auth";
import { groupHeaderUrl } from "@/utils/apiUtils";
import "./styles.less";


export function Header() {
const authContext = useContext(AuthContext);
const imageLogoRef : any = createRef();

Check warning on line 12 in src/components/UniversiHeader/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UniversiHeader/index.tsx#L11-L12

Added lines #L11 - L12 were not covered by tests

function imgLogoLoadError(): any {
imageLogoRef.current.onError = "";
imageLogoRef.current.src = `/assets/imgs/organization-headers/codata.png`;

Check warning on line 16 in src/components/UniversiHeader/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UniversiHeader/index.tsx#L14-L16

Added lines #L14 - L16 were not covered by tests
}

return (
<header id="header">
<div className="logo-container">
{ authContext?.profile &&
<div className="logo-container">

Check warning on line 22 in src/components/UniversiHeader/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UniversiHeader/index.tsx#L22

Added line #L22 was not covered by tests
<img src="/assets/imgs/universi-me2.png"/>
</div>
</div>
}
<div className="left-items">
<Link to="/" id="header-logo">
<img src={getHeaderLogoUrl()} className="organization-logo" alt="" />
<Link to={authContext?.profile ? `/group` + authContext.organization?.path as string : `/`} id="header-logo">
<img src={groupHeaderUrl(authContext.organization!)} className="organization-logo" alt="" onError={imgLogoLoadError} ref={imageLogoRef} title={authContext.organization?.name} />
</Link>
</div>
<div className="right-items">
Expand All @@ -21,15 +34,3 @@ export function Header() {
</header>
);
}

function getHeaderLogoUrl() {
const match = REGEXP_MATCH_SUBDOMAIN.exec(location.hostname);
let subdomain = match ? match[1] : undefined;

if (!subdomain)
subdomain = "codata";

return `/assets/imgs/organization-headers/${subdomain}.png`
}

const REGEXP_MATCH_SUBDOMAIN = /^(?:[a-z]{3,5}:\/\/)?([^\.]*)?\.universi\.me/;
6 changes: 5 additions & 1 deletion src/components/UniversiHeader/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

}

.logo-container + .left-items {
padding-left: 0.5rem;
}

.organization-logo{
height: inherit;
width: auto;
Expand Down Expand Up @@ -59,7 +63,7 @@
}

.left-items{
padding-left: 0.5rem;
padding-left: 5rem;
height: 100%;
overflow: hidden;
img{
Expand Down
2 changes: 1 addition & 1 deletion src/services/UniversimeApi/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type LogOut_ResponseDTO = ApiResponse;

export async function validateToken() {
const response = await api.get<GetAccount_ResponseDTO>('/account');
return response.data.body;
return response.data.body?.user ?? null;
}

export async function signin({ username, password, recaptchaToken }: SignIn_RequestDTO) {
Expand Down
1 change: 1 addition & 0 deletions src/types/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type Group = {
publicGroup: boolean;
rootGroup: boolean;
bannerImage: string | null;
headerImage: string | null;
organization: Group | null;
canEdit: boolean;
everyoneCanPost: boolean;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export function groupBannerUrl(group: Group) {
return `${import.meta.env.VITE_UNIVERSIME_API}/group/banner/${group.id}`;
}

export function groupHeaderUrl(group: Group) {
if(group?.headerImage) {
return group?.headerImage.startsWith('/') ? import.meta.env.VITE_UNIVERSIME_API + group?.headerImage : group?.headerImage;
}
return `/assets/imgs/organization-headers/${group?.nickname ?? `codata`}.png`
}

export function groupImageUrl(group: Group) {
if(!group.image)
return "/assets/imgs/group.png"
Expand Down

0 comments on commit 33bb71a

Please sign in to comment.