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

refactor: use antd form in organization display name #2006

Merged
merged 4 commits into from
Jan 10, 2023
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
45 changes: 23 additions & 22 deletions frontend/src/container/OrganizationSettings/DisplayName/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Input, notification, Space, Typography } from 'antd';
import { Button, Form, Input, notification } from 'antd';
import editOrg from 'api/user/editOrg';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -14,14 +14,15 @@ function DisplayName({
id: orgId,
isAnonymous,
}: DisplayNameProps): JSX.Element {
const [form] = Form.useForm();

const { t } = useTranslation(['organizationsettings', 'common']);
const { org } = useSelector<AppState, AppReducer>((state) => state.app);
const { name } = (org || [])[index];
const [orgName, setOrgName] = useState<string>(name);
const [isLoading, setIsLoading] = useState<boolean>(false);
const dispatch = useDispatch<Dispatch<AppActions>>();

const onClickHandler = async (): Promise<void> => {
const onSubmit = async ({ name: orgName }: OnSubmitProps): Promise<void> => {
try {
setIsLoading(true);
const { statusCode, error } = await editOrg({
Expand Down Expand Up @@ -67,26 +68,22 @@ function DisplayName({
}

return (
<Space direction="vertical">
<Typography.Title level={3}>{t('display_name')}</Typography.Title>
<Space direction="vertical" size="middle">
<Input
value={orgName}
onChange={(e): void => setOrgName(e.target.value)}
size="large"
placeholder={t('signoz')}
disabled={isLoading}
/>
<Button
onClick={onClickHandler}
disabled={isLoading || orgName === name}
loading={isLoading}
type="primary"
>
Change Org Name
<Form
initialValues={{ name }}
form={form}
layout="vertical"
onFinish={onSubmit}
autoComplete="off"
>
<Form.Item name="name" label="Display name" rules={[{ required: true }]}>
<Input size="large" placeholder={t('signoz')} disabled={isLoading} />
</Form.Item>
<Form.Item>
<Button loading={isLoading} type="primary" htmlType="submit">
Submit
</Button>
</Space>
</Space>
</Form.Item>
</Form>
);
}

Expand All @@ -96,4 +93,8 @@ interface DisplayNameProps {
isAnonymous: boolean;
}

interface OnSubmitProps {
name: string;
}

export default DisplayName;