2021-10-07 16:14:35 -07:00
|
|
|
import React, { useState } from 'react';
|
2022-02-01 10:47:45 -08:00
|
|
|
import { message, Button, Input, Modal, Typography, Form, Collapse } from 'antd';
|
2021-10-07 16:14:35 -07:00
|
|
|
import { useCreateGroupMutation } from '../../../graphql/group.generated';
|
2022-02-17 04:30:54 +05:30
|
|
|
import { useEnterKeyListener } from '../../shared/useEnterKeyListener';
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
visible: boolean;
|
|
|
|
onClose: () => void;
|
|
|
|
onCreate: (name: string, description: string) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function CreateGroupModal({ visible, onClose, onCreate }: Props) {
|
|
|
|
const [stagedName, setStagedName] = useState('');
|
|
|
|
const [stagedDescription, setStagedDescription] = useState('');
|
2022-02-01 10:47:45 -08:00
|
|
|
const [stagedId, setStagedId] = useState<string | undefined>(undefined);
|
2021-10-07 16:14:35 -07:00
|
|
|
const [createGroupMutation] = useCreateGroupMutation();
|
|
|
|
|
|
|
|
const onCreateGroup = () => {
|
|
|
|
createGroupMutation({
|
|
|
|
variables: {
|
|
|
|
input: {
|
2022-02-01 10:47:45 -08:00
|
|
|
id: stagedId,
|
2021-10-07 16:14:35 -07:00
|
|
|
name: stagedName,
|
|
|
|
description: stagedDescription,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
message.destroy();
|
|
|
|
message.error({ content: `Failed to create group!: \n ${e.message || ''}`, duration: 3 });
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
message.success({
|
|
|
|
content: `Created group!`,
|
|
|
|
duration: 3,
|
|
|
|
});
|
|
|
|
onCreate(stagedName, stagedDescription);
|
|
|
|
setStagedName('');
|
|
|
|
setStagedDescription('');
|
|
|
|
});
|
|
|
|
onClose();
|
|
|
|
};
|
|
|
|
|
2022-02-17 04:30:54 +05:30
|
|
|
// Handle the Enter press
|
|
|
|
useEnterKeyListener({
|
|
|
|
querySelectorToExecuteClick: '#createGroupButton',
|
|
|
|
});
|
|
|
|
|
2021-10-07 16:14:35 -07:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title="Create new group"
|
|
|
|
visible={visible}
|
|
|
|
onCancel={onClose}
|
|
|
|
footer={
|
|
|
|
<>
|
|
|
|
<Button onClick={onClose} type="text">
|
|
|
|
Cancel
|
|
|
|
</Button>
|
2022-02-17 04:30:54 +05:30
|
|
|
<Button id="createGroupButton" onClick={onCreateGroup} disabled={stagedName === ''}>
|
2021-10-07 16:14:35 -07:00
|
|
|
Create
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Form layout="vertical">
|
|
|
|
<Form.Item name="name" label={<Typography.Text strong>Name</Typography.Text>}>
|
|
|
|
<Typography.Paragraph>Give your new group a name.</Typography.Paragraph>
|
|
|
|
<Input
|
|
|
|
placeholder="A name for your group"
|
|
|
|
value={stagedName}
|
|
|
|
onChange={(event) => setStagedName(event.target.value)}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item name="description" label={<Typography.Text strong>Description</Typography.Text>}>
|
|
|
|
<Typography.Paragraph>An optional description for your new group.</Typography.Paragraph>
|
|
|
|
<Input
|
|
|
|
placeholder="A description for your group"
|
|
|
|
value={stagedDescription}
|
|
|
|
onChange={(event) => setStagedDescription(event.target.value)}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
2022-02-01 10:47:45 -08:00
|
|
|
<Collapse ghost>
|
|
|
|
<Collapse.Panel header={<Typography.Text type="secondary">Advanced</Typography.Text>} key="1">
|
|
|
|
<Form.Item label={<Typography.Text strong>Group Id</Typography.Text>}>
|
|
|
|
<Typography.Paragraph>
|
|
|
|
By default, a random UUID will be generated to uniquely identify this group. If
|
|
|
|
you'd like to provide a custom id instead to more easily keep track of this group,
|
|
|
|
you may provide it here. Be careful, you cannot easily change the group id after
|
|
|
|
creation.
|
|
|
|
</Typography.Paragraph>
|
|
|
|
<Input
|
|
|
|
placeholder="product_engineering"
|
|
|
|
value={stagedId || ''}
|
|
|
|
onChange={(event) => setStagedId(event.target.value)}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
</Collapse.Panel>
|
|
|
|
</Collapse>
|
2021-10-07 16:14:35 -07:00
|
|
|
</Form>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|