Styling of Authorize page

This commit is contained in:
Tom Moor committed 2025-04-03 21:43:04 -04:00
1 parent 24eaeca47e
commit 79df4b030b
2 files changed
+97 -14

No files matched your search

+90 -14
View File
@@ -1,8 +1,14 @@
import { MoreIcon } from "outline-icons";
import React from "react";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import Flex from "@shared/components/Flex";
import { s } from "@shared/styles";
import { Avatar, AvatarSize } from "~/components/Avatar";
import Button from "~/components/Button";
import ChangeLanguage from "~/components/ChangeLanguage";
import TeamLogo from "~/components/TeamLogo";
import Heading from "~/components/Heading";
import Text from "~/components/Text";
import useCurrentTeam from "~/hooks/useCurrentTeam";
import useQuery from "~/hooks/useQuery";
import useRequest from "~/hooks/useRequest";
@@ -21,10 +27,12 @@ function Authorize() {
const responseType = params.get("response_type");
const state = params.get("state");
const scope = params.get("scope");
// const [scopes] = React.useState(() => scope?.split(" ") ?? []);
const { error, data, request } = useRequest(() =>
client.post("/oauthClients.info", { clientId })
);
const [scopes] = React.useState(() => scope?.split(" ") ?? []);
const {
error,
data: response,
request,
} = useRequest(() => client.post("/oauthClients.info", { clientId }));
React.useEffect(() => {
if (clientId) {
@@ -32,19 +40,50 @@ function Authorize() {
}
}, []);
const missingParams = [
!clientId && "client_id",
!clientSecret && "client_secret",
!redirectUri && "redirect_uri",
!responseType && "response_type",
!state && "state",
!scope && "scope",
].filter(Boolean);
if (missingParams.length) {
return (
<Background>
<ChangeLanguage locale={detectLanguage()} />
<Centered>
<StyledHeading>{t("Error")}</StyledHeading>
<Text as="p" type="secondary">
{t("Required OAuth parameters are missing")}
<Pre>
{missingParams.map((param) => (
<>
{param}
<br />
</>
))}
</Pre>
</Text>
</Centered>
</Background>
);
}
if (error) {
return (
<Background>
<ChangeLanguage locale={detectLanguage()} />
<Centered>
<h1>{t("Error")}</h1>
<StyledHeading>{t("Error")}</StyledHeading>
<p>{t("Unable to load OAuth client")}</p>
</Centered>
</Background>
);
}
if (!data) {
if (!response) {
// TODO
return null;
}
@@ -54,11 +93,29 @@ function Authorize() {
<ChangeLanguage locale={detectLanguage()} />
<Centered gap={12}>
<TeamLogo model={team} size={24} alt={t("Logo")} /> {team.name}
<h1>{data.data.name}</h1>
<p>{data.data.developerName}</p>
<p>{data.data.developerUrl}</p>
<p>{data.data.description}</p>
<Flex gap={8} align="center">
<Logo
model={{
avatarUrl: response.data.avatarUrl,
initial: response.data.name[0],
}}
size={AvatarSize.XXLarge}
alt={t("Logo")}
/>{" "}
<MoreIcon />{" "}
<Logo model={team} size={AvatarSize.XXLarge} alt={t("Logo")} />
</Flex>
<StyledHeading>
{response.data.name} wants to access {team.name}
</StyledHeading>
<p>
{scopes.map((item) => (
<>
{item}
<br />
</>
))}
</p>
<form method="POST" action="/oauth/authorize" style={{ width: "100%" }}>
<input type="hidden" name="client_id" value={clientId ?? ""} />
<input
@@ -70,11 +127,11 @@ function Authorize() {
<input
type="hidden"
name="response_type"
value={responseType ?? "code"}
value={responseType ?? ""}
/>
<input type="hidden" name="state" value={state ?? ""} />
<input type="hidden" name="scope" value={scope ?? ""} />
<Button type="submit" fullwidth>
<Button type="submit" large fullwidth>
{t("Authorize")}
</Button>
</form>
@@ -83,4 +140,23 @@ function Authorize() {
);
}
const Logo = styled(Avatar)`
border-radius: 8px;
`;
const StyledHeading = styled(Heading).attrs({
as: "h2",
centered: true,
})`
margin-top: 0;
`;
const Pre = styled.pre`
background: ${s("backgroundSecondary")};
padding: 16px;
border-radius: 4px;
font-size: 12px;
white-space: pre-wrap;
`;
export default Authorize;
@@ -118,6 +118,7 @@
"Log out": "Log out",
"Mark notifications as read": "Mark notifications as read",
"Archive all notifications": "Archive all notifications",
"New App": "New App",
"Restore revision": "Restore revision",
"Link copied": "Link copied",
"Dark": "Dark",
@@ -515,6 +516,7 @@
"Features": "Features",
"Members": "Members",
"Groups": "Groups",
"Applications": "Applications",
"Shared Links": "Shared Links",
"Import": "Import",
"Self Hosted": "Self Hosted",
@@ -820,6 +822,9 @@
"You signed in with {{ authProviderName }} last time.": "You signed in with {{ authProviderName }} last time.",
"Or": "Or",
"Already have an account? Go to <1>login</1>.": "Already have an account? Go to <1>login</1>.",
"Required OAuth parameters are missing": "Required OAuth parameters are missing",
"Unable to load OAuth client": "Unable to load OAuth client",
"Authorize": "Authorize",
"Any collection": "Any collection",
"All time": "All time",
"Past day": "Past day",
@@ -837,6 +842,7 @@
"No documents found for your search filters.": "No documents found for your search filters.",
"API": "API",
"API keys can be used to authenticate with the API and programatically control\n your workspace's data. For more details see the <em>developer documentation</em>.": "API keys can be used to authenticate with the API and programatically control\n your workspace's data. For more details see the <em>developer documentation</em>.",
"OAuth apps can be used to authenticate with the API and programatically control\n your workspace's data. For more details see the <em>developer documentation</em>.": "OAuth apps can be used to authenticate with the API and programatically control\n your workspace's data. For more details see the <em>developer documentation</em>.",
"by {{ name }}": "by {{ name }}",
"Last used": "Last used",
"No expiry": "No expiry",
@@ -908,6 +914,7 @@
"Drag and drop the zip file from Notion's HTML export option, or click to upload": "Drag and drop the zip file from Notion's HTML export option, or click to upload",
"Last active": "Last active",
"Guest": "Guest",
"Client secret copied to clipboard": "Client secret copied to clipboard",
"Shared by": "Shared by",
"Date shared": "Date shared",
"Last accessed": "Last accessed",