Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
feat: Basic auth for projects (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
HideBa committed Jun 3, 2021
1 parent b367404 commit 372c4e8
Show file tree
Hide file tree
Showing 9 changed files with 8,870 additions and 8,558 deletions.
2 changes: 1 addition & 1 deletion src/components/molecules/Settings/Field/index.tsx
Expand Up @@ -8,7 +8,7 @@ type Props = {
header?: React.ReactNode;
action?: React.ReactNode;
secondaryAction?: React.ReactNode;
body?: string;
body?: React.ReactNode;
children?: React.ReactNode;
};

Expand Down
@@ -0,0 +1,53 @@
import { styled } from "@reearth/theme";
import React from "react";
import { useIntl } from "react-intl";
import Section from "../../Section";
import EditableItem from "../EditableItem";
import ToggleItem from "../ToggleItem";

export type Props = {
onSave: (active?: boolean, basicAuthUsername?: string, basicAuthPassword?: string) => void;
isBasicAuthActive?: boolean;
basicAuthUsername?: string;
basicAuthPassword?: string;
};

const BasicAuthSection: React.FC<Props> = ({
onSave,
isBasicAuthActive,
basicAuthUsername,
basicAuthPassword,
}) => {
const intl = useIntl();
return (
<Wrapper>
<Section title={intl.formatMessage({ defaultMessage: "Basic Authorization" })}>
<ToggleItem
title={intl.formatMessage({ defaultMessage: "Enable basic authorization" })}
checked={!!isBasicAuthActive}
onChange={() => onSave(!isBasicAuthActive, basicAuthUsername, basicAuthPassword)}
/>
<EditableItem
title={intl.formatMessage({ defaultMessage: "Username" })}
body={basicAuthUsername}
multilineTextBox={false}
onSubmit={username => onSave(isBasicAuthActive, username, basicAuthPassword)}
/>
<EditableItem
title={intl.formatMessage({ defaultMessage: "Password" })}
body={basicAuthPassword}
multilineTextBox={false}
onSubmit={password => onSave(isBasicAuthActive, basicAuthUsername, password)}
/>
</Section>
</Wrapper>
);
};

const Wrapper = styled.div`
width: 100%;
background-color: ${({ theme }) => theme.colors.bg[3]};
margin-bottom: 64px;
`;

export default BasicAuthSection;
15 changes: 15 additions & 0 deletions src/components/molecules/Settings/Project/ToggleItem/index.tsx
@@ -0,0 +1,15 @@
import ToggleButton from "@reearth/components/atoms/ToggleButton";
import React from "react";
import Field from "../../Field";

export type Props = {
checked: boolean;
title: string;
onChange?: () => void;
};

const ToggleItem: React.FC<Props> = ({ title, onChange, checked }) => {
return <Field header={title} body={<ToggleButton checked={checked} onChange={onChange} />} />;
};

export default ToggleItem;
16 changes: 16 additions & 0 deletions src/components/organisms/Settings/Project/hooks.ts
Expand Up @@ -9,6 +9,7 @@ import {
useCheckProjectAliasLazyQuery,
useArchiveProjectMutation,
useDeleteProjectMutation,
useUpdateProjectBasicAuthMutation,
} from "@reearth/gql";
import { useLocalState } from "@reearth/state";

Expand Down Expand Up @@ -43,6 +44,9 @@ export default ({ projectId }: Params) => {
publicTitle: rawProject.publicTitle,
publicDescription: rawProject.publicDescription,
isArchived: rawProject.isArchived,
isBasicAuthActive: rawProject.isBasicAuthActive,
basicAuthUsername: rawProject.basicAuthUsername,
basicAuthPassword: rawProject.basicAuthPassword,
imageUrl: rawProject.imageUrl,
alias: rawProject.alias,
publishmentStatus: rawProject.publishmentStatus,
Expand All @@ -52,6 +56,7 @@ export default ({ projectId }: Params) => {
);

// Project Updating
const [updateProjectBasicAuthMutation] = useUpdateProjectBasicAuthMutation();
const [updateProjectNameMutation] = useUpdateProjectNameMutation();
const [updateProjectDescriptionMutation] = useUpdateProjectDescriptionMutation();
const [updateProjectImageUrlMutation] = useUpdateProjectImageUrlMutation();
Expand All @@ -71,6 +76,16 @@ export default ({ projectId }: Params) => {
projectId && deleteProjectMutation({ variables: { projectId } });
}, [projectId, deleteProjectMutation]);

const updateProjectBasicAuth = useCallback(
(isBasicAuthActive?: boolean, basicAuthUsername?: string, basicAuthPassword?: string) => {
projectId &&
updateProjectBasicAuthMutation({
variables: { projectId, isBasicAuthActive, basicAuthUsername, basicAuthPassword },
});
},
[projectId, updateProjectBasicAuthMutation],
);

const updateProjectDescription = useCallback(
(description: string) => {
projectId && updateProjectDescriptionMutation({ variables: { projectId, description } });
Expand Down Expand Up @@ -145,6 +160,7 @@ export default ({ projectId }: Params) => {
project,
projectId,
currentTeam,
updateProjectBasicAuth,
updateProjectName,
updateProjectDescription,
updateProjectImageUrl,
Expand Down
8 changes: 8 additions & 0 deletions src/components/organisms/Settings/Project/index.tsx
Expand Up @@ -8,6 +8,7 @@ import ProfileSection from "@reearth/components/molecules/Settings/Project/Profi
import PublishSection from "@reearth/components/molecules/Settings/Project/PublishSection";
import DangerSection from "@reearth/components/molecules/Settings/Project/DangerSection";
import ArchivedMessage from "@reearth/components/molecules/Settings/Project/ArchivedMessage";
import BasicAuthSection from "@reearth/components/molecules/Settings/Project/BasicAuthSection";

type Props = {
projectId: string;
Expand All @@ -17,6 +18,7 @@ const Project: React.FC<Props> = ({ projectId }) => {
const {
project,
currentTeam,
updateProjectBasicAuth,
updateProjectName,
updateProjectDescription,
updateProjectImageUrl,
Expand All @@ -37,6 +39,12 @@ const Project: React.FC<Props> = ({ projectId }) => {
{!project?.isArchived && (
<>
<StatusSection projectStatus={projectStatus} />
<BasicAuthSection
onSave={updateProjectBasicAuth}
isBasicAuthActive={project?.isBasicAuthActive}
basicAuthUsername={project?.basicAuthUsername ?? ""}
basicAuthPassword={project?.basicAuthPassword ?? ""}
/>
<ProfileSection
currentProject={project}
updateProjectName={updateProjectName}
Expand Down
47 changes: 47 additions & 0 deletions src/components/organisms/Settings/Project/queries.ts
Expand Up @@ -8,6 +8,9 @@ export const PROJECT = gql`
name
description
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
imageUrl
Expand All @@ -18,6 +21,32 @@ export const PROJECT = gql`
}
`;

export const UPDATE_PROJECT_BASIC_AUTH = gql`
mutation updateProjectBasicAuth(
$projectId: ID!
$isBasicAuthActive: Boolean
$basicAuthUsername: String
$basicAuthPassword: String
) {
updateProject(
input: {
projectId: $projectId
isBasicAuthActive: $isBasicAuthActive
basicAuthUsername: $basicAuthUsername
basicAuthPassword: $basicAuthPassword
}
) {
project {
id
name
isBasicAuthActive
basicAuthUsername
basicAuthPassword
}
}
}
`;

export const UPDATE_PROJECT_NAME = gql`
mutation updateProjectName($projectId: ID!, $name: String!) {
updateProject(input: { projectId: $projectId, name: $name }) {
Expand All @@ -26,6 +55,9 @@ export const UPDATE_PROJECT_NAME = gql`
name
description
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
imageUrl
Expand All @@ -44,6 +76,9 @@ export const UPDATE_PROJECT_DESCRIPTION = gql`
name
description
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
imageUrl
Expand All @@ -62,6 +97,9 @@ export const UPDATE_PROJECT_IMAGE_URL = gql`
name
description
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
imageUrl
Expand All @@ -80,6 +118,9 @@ export const UPDATE_PROJECT_PUBLIC_TITLE = gql`
name
description
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
imageUrl
Expand All @@ -98,6 +139,9 @@ export const UPDATE_PROJECT_PUBLIC_DESCRIPTION = gql`
name
description
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
imageUrl
Expand All @@ -116,6 +160,9 @@ export const ARCHIVE_PROJECT = gql`
name
description
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
imageUrl
Expand Down
14 changes: 7 additions & 7 deletions src/gql/fragmentMatcher.json
Expand Up @@ -4,16 +4,12 @@
"Asset",
"Scene",
"DatasetSchemaField",
"Project",
"Property",
"User",
"DatasetSchema",
"Team",
"Dataset",
"Project"
],
"Layers": [
"LayerItem",
"LayerGroup"
"DatasetSchema",
"User"
],
"PropertyItem": [
"PropertyGroup",
Expand All @@ -22,6 +18,10 @@
"Layer": [
"LayerGroup",
"LayerItem"
],
"Layers": [
"LayerItem",
"LayerGroup"
]
}
}

0 comments on commit 372c4e8

Please sign in to comment.