Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Form tag into AuthInput #15

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 55 additions & 41 deletions src/Components/AuthInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class AuthInput extends React.Component<{
dbId: string,
isAuthButtonEnable: boolean,
isAuthFailed: boolean,
isOpen: boolean
isOpen: boolean,
isLoading: boolean,
}> {

constructor(props: any) {
Expand All @@ -22,6 +23,7 @@ export class AuthInput extends React.Component<{
isAuthButtonEnable: this.checkIsAuthButtonEnable(this.props.token, this.props.dbId),
isAuthFailed: false,
isOpen: true,
isLoading: false,
};
}
render() {
Expand All @@ -38,52 +40,59 @@ export class AuthInput extends React.Component<{
title={'Authentication Required'}
icon={'info-sign'}
>
<div className={Classes.DIALOG_BODY}>
<p>
<strong>To use this application, authentication on Notion is required first.</strong>
<form>
<div className={Classes.DIALOG_BODY}>
<p>
<strong>To use this application, authentication on Notion is required first.</strong>
</p>
<ol>
<li>Refer to <strong><a href="https://developers.notion.com/docs/create-a-notion-integration" target="_blank">this page</a></strong> and create an internal integration.</li>
<li>Enter the <strong>Integration Token</strong> and <strong>Database ID</strong> you obtained.</li>
<li>Press "Authenticate" button.</li>
</ol>
</p>
<FormGroup
label="Integration Token"
labelFor="text-input"
labelInfo="(required)"
>
<InputGroup
id="text-input"
placeholder="Integration Token"
value={this.state.token}
onChange={this.handleChangeToken}
intent={this.state.isAuthFailed ? Intent.DANGER : Intent.NONE}
/>
</FormGroup>
<FormGroup
label="Integration Token"
labelFor="token-input"
labelInfo="(required)"
>
<InputGroup
id="token-input"
placeholder="Integration Token"
value={this.state.token}
disabled={this.state.isLoading}
onChange={this.handleChangeToken}
intent={this.state.isAuthFailed ? Intent.DANGER : Intent.NONE}
/>
</FormGroup>

<FormGroup
label="Database ID"
labelFor="text-input"
labelInfo="(required)"
>
<InputGroup
id="text-input"
placeholder="Database ID"
value={this.state.dbId}
onChange={this.handleChangeDbId}
intent={this.state.isAuthFailed ? Intent.DANGER : Intent.NONE}
/>
</FormGroup>
</div>
<div className={Classes.DIALOG_FOOTER}>
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
<Button
intent={'primary'}
disabled={!this.state.isAuthButtonEnable}
onClick={this.handleClickAuthButton}
>Authenticate</Button>
<FormGroup
label="Database ID"
labelFor="dbid-input"
labelInfo="(required)"
>
<InputGroup
id="dbid-input"
placeholder="Database ID"
value={this.state.dbId}
disabled={this.state.isLoading}
onChange={this.handleChangeDbId}
intent={this.state.isAuthFailed ? Intent.DANGER : Intent.NONE}
/>
</FormGroup>
</div>
</div>
<div className={Classes.DIALOG_FOOTER}>
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
<Button
id="authenticate-button"
intent={'primary'}
loading={this.state.isLoading}
disabled={!this.state.isAuthButtonEnable}
onClick={this.handleClickAuthButton}
type="submit"
>Authenticate</Button>
</div>
</div>
</form>
</Dialog>
);
}
Expand All @@ -104,7 +113,10 @@ export class AuthInput extends React.Component<{
return token !== '' && dbId !== '';
}

private handleClickAuthButton = () => {
private handleClickAuthButton = (event: React.MouseEvent<HTMLElement, MouseEvent>) => {
event.preventDefault();

this.setState({ isLoading: true });
const notion = new NotionHandler(this.state.token, this.state.dbId);
notion.verifyConnectivity().then((result) => {
if (result.isOk) {
Expand All @@ -123,6 +135,8 @@ export class AuthInput extends React.Component<{
});
this.setState({ isAuthFailed: true });
}
}).finally(()=>{
this.setState({ isLoading: false });
});
}

Expand Down
1 change: 0 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ReactDOM from "react-dom/client";
import { App } from "./App";
import "./style.css";
//import { dbId, token } from "./TOKEN";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
//Commented out because `componentDidMount` is called twice if `React.StrictMode` is enabled.
Expand Down