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

feat(web): add the button to copy the value of Integration Token #1164

Merged
merged 1 commit into from
May 22, 2024
Merged
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
27 changes: 25 additions & 2 deletions web/src/components/molecules/MyIntegrations/Settings/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import styled from "@emotion/styled";
import { useCallback } from "react";
import { useCallback, useMemo } from "react";

import Button from "@reearth-cms/components/atoms/Button";
import Col from "@reearth-cms/components/atoms/Col";
import Divider from "@reearth-cms/components/atoms/Divider";
import Form from "@reearth-cms/components/atoms/Form";
import Icon from "@reearth-cms/components/atoms/Icon";
import Input from "@reearth-cms/components/atoms/Input";
import Modal from "@reearth-cms/components/atoms/Modal";
import Row from "@reearth-cms/components/atoms/Row";
Expand Down Expand Up @@ -49,6 +50,13 @@ const MyIntegrationForm: React.FC<Props> = ({
});
}, [t, onRegenerateToken]);

const copyIcon = useMemo(() => {
const onClick = () => {
if (integration.config.token) navigator.clipboard.writeText(integration.config.token);
};
return <Icon icon="copy" onClick={onClick} />;
}, [integration.config.token]);

return (
<Form form={form} layout="vertical" initialValues={integration}>
<Row gutter={32}>
Expand All @@ -68,7 +76,11 @@ const MyIntegrationForm: React.FC<Props> = ({
<TextArea rows={3} showCount maxLength={100} />
</Form.Item>
<Form.Item label={t("Integration Token")}>
<StyledTokenInput value={integration.config.token} contentEditable={false} />
<StyledTokenInput
value={integration.config.token}
contentEditable={false}
prefix={copyIcon}
/>
<StyledRegenerateTokenButton type="primary" onClick={handleRegenerateToken}>
{t("Regenerate")}
</StyledRegenerateTokenButton>
Expand Down Expand Up @@ -124,6 +136,17 @@ const StyledDivider = styled(Divider)`

const StyledTokenInput = styled(Input.Password)`
width: calc(100% - 120px);
.ant-input-prefix {
order: 1;
margin-left: 4px;
color: rgb(0, 0, 0, 0.45);
:hover {
color: rgba(0, 0, 0, 0.88);
}
}
.ant-input-suffix {
order: 2;
}
`;

const StyledRegenerateTokenButton = styled(Button)`
Expand Down
Loading