-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
563 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {theme} from 'antd'; | ||
import React from 'react'; | ||
|
||
const {useToken} = theme; | ||
|
||
const BorderedContainer = (props:React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>) => { | ||
const {token} = useToken(); | ||
return <div {...props} style={{backgroundColor: token.colorBgElevated,borderRadius:token.borderRadius,border:`1px solid ${token.colorBorder}`}} >{props.children}</div>; | ||
}; | ||
|
||
export default BorderedContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import {Tag, Form, Input, Button, ColorPicker} from 'antd'; | ||
import type {FormInstance} from 'antd/es/form'; | ||
import {useRouter} from 'next/router'; | ||
import React, {useEffect} from 'react'; | ||
import {useProjectStore} from '../../store/project.store'; | ||
import {api} from '../../utils/api'; | ||
|
||
import {ReloadOutlined} from '@ant-design/icons'; | ||
import type {Label} from '@prisma/client'; | ||
|
||
type FieldType = { | ||
title: string; | ||
description?: string; | ||
color: string; | ||
}; | ||
|
||
interface Props { | ||
form: FormInstance; | ||
forEdit?: boolean; | ||
onCancel?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void; | ||
layout?: 'vertical' | 'horizontal'; | ||
onFinish?: (value: Label) => void; | ||
} | ||
|
||
const LabelForm = (props: Props) => { | ||
const router = useRouter(); | ||
const {projectId} = router.query; | ||
const {addLabel, editLabel} = useProjectStore(); | ||
|
||
useEffect(() => { | ||
if (props.forEdit) { | ||
props.form.setFieldsValue({ | ||
title: props.form.getFieldValue('title'), | ||
description: props.form.getFieldValue('description'), | ||
color: props.form.getFieldValue('color'), | ||
}); | ||
} | ||
}, [props.forEdit, props.form]); | ||
|
||
const {mutate: createLabel, isLoading: isCreating} = | ||
api.project.createProjectLabels.useMutation({ | ||
onSuccess: (data) => { | ||
addLabel(data); | ||
props.form.resetFields(); | ||
props.onFinish?.(data); | ||
}, | ||
}); | ||
|
||
const {mutate: editLabelAPI, isLoading: isEditing} = | ||
api.project.updateProjectLabel.useMutation({ | ||
onSuccess: (data) => { | ||
editLabel(data); | ||
props.onFinish?.(data); | ||
}, | ||
}); | ||
|
||
const handleSubmit = (values: FieldType) => { | ||
if (props.forEdit) { | ||
editLabelAPI({ | ||
id: props.form.getFieldValue('id'), | ||
title: values.title, | ||
color: values.color, | ||
description: values.description, | ||
}); | ||
return; | ||
} | ||
createLabel({ | ||
projectId: projectId as string, | ||
title: values.title, | ||
color: values.color, | ||
description: values.description, | ||
}); | ||
}; | ||
|
||
const getRandomColor = () => { | ||
const letters = '0123456789ABCDEF'; | ||
let color = '#'; | ||
for (let i = 0; i < 6; ++i) { | ||
color += letters[Math.floor(Math.random() * 16)]; | ||
} | ||
return color; | ||
}; | ||
const color: string = Form.useWatch('color', props.form); | ||
const titleValue: string = Form.useWatch('name', props.form); | ||
const getNameValue = () => { | ||
if (titleValue === undefined || titleValue.length === 0) | ||
return 'Label preview'; | ||
|
||
return titleValue ?? 'Label preview'; | ||
}; | ||
|
||
return ( | ||
<> | ||
<Tag color={color} className="mb-3"> | ||
{getNameValue()} | ||
</Tag> | ||
<Form | ||
form={props.form} | ||
name={props.forEdit ? 'edit-label' : 'create-label'} | ||
layout="vertical" | ||
autoComplete="off" | ||
className={`flex ${ | ||
props.layout === 'vertical' ? 'flex-col' : 'items-end gap-1' | ||
} jusify-between `} | ||
onFinish={handleSubmit} | ||
initialValues={{ | ||
color: getRandomColor(), | ||
}} | ||
> | ||
<Form.Item<FieldType> | ||
name="title" | ||
label="Title" | ||
rules={[{required: true}, {min: 4}]} | ||
> | ||
<Input /> | ||
</Form.Item> | ||
<Form.Item<FieldType> name="description" label="Description"> | ||
<Input /> | ||
</Form.Item> | ||
<div className="flex gap-1-2 items-center"> | ||
<Form.Item<FieldType> name="color" label="Color" required> | ||
<ColorPicker | ||
showText | ||
disabledAlpha | ||
value={color} | ||
onChange={(_, hex) => { | ||
props.form.setFieldsValue({color: hex}); | ||
}} | ||
presets={[ | ||
{ | ||
label: 'Recommended', | ||
colors: [ | ||
'#F5222D', | ||
'#FA8C16', | ||
'#FADB14', | ||
'#8BBB11', | ||
'#52C41A', | ||
'#13A8A8', | ||
'#1677FF', | ||
'#2F54EB', | ||
'#722ED1', | ||
'#EB2F96', | ||
], | ||
}, | ||
]} | ||
/> | ||
</Form.Item> | ||
<Button | ||
type="primary" | ||
style={{backgroundColor: color}} | ||
icon={<ReloadOutlined color={color} />} | ||
onClick={() => { | ||
props.form.setFieldsValue({color: getRandomColor()}); | ||
}} | ||
/> | ||
</div> | ||
|
||
<Form.Item className="flex-1 flex justify-end"> | ||
<div className="flex gap-1-2"> | ||
<Button type="default" onClick={props.onCancel}> | ||
Cancel | ||
</Button> | ||
<Button | ||
type="primary" | ||
onClick={props.form.submit} | ||
loading={isCreating || isEditing} | ||
> | ||
{props.forEdit ? 'Edit Label' : ' Create Label'} | ||
</Button> | ||
</div> | ||
</Form.Item> | ||
</Form> | ||
</> | ||
); | ||
}; | ||
|
||
export default LabelForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import Board from './Board'; | ||
|
||
import type {ReactNode} from 'react'; | ||
import {Button, Divider, Typography} from 'antd'; | ||
import {useRouter} from 'next/router'; | ||
|
||
import {InfoCircleOutlined, TagsOutlined} from '@ant-design/icons'; | ||
|
||
const {Title} = Typography; | ||
|
||
const SettingsLayout = ({children}: {children: ReactNode}) => { | ||
const settingsOptions = [ | ||
{ | ||
icon: <InfoCircleOutlined />, | ||
label: 'Overview', | ||
route: 'settings', | ||
href: '', | ||
}, | ||
{ | ||
icon: <TagsOutlined />, | ||
label: 'Labels', | ||
route: 'labels', | ||
href: 'labels', | ||
}, | ||
]; | ||
const router = useRouter(); | ||
return ( | ||
<> | ||
<Board> | ||
<Title level={4} className='mb-0'>Settings</Title> | ||
<div className="flex gap-1-2"> | ||
{settingsOptions.map((option, index) => { | ||
const key = String(index + 1); | ||
return ( | ||
<Button | ||
key={key} | ||
type={ | ||
router.pathname.split('/')[ | ||
router.pathname.split('/').length - 1 | ||
] == option.route | ||
? 'default' | ||
: 'text' | ||
} | ||
icon={option.icon} | ||
onClick={() => | ||
router.push({ | ||
pathname: `/w/${router.query.workspaceId}/projects/${router.query.projectId}/settings/${option.href}`, | ||
}) | ||
} | ||
> | ||
{option.label} | ||
</Button> | ||
); | ||
})} | ||
</div> | ||
<Divider dashed className="my-1" /> | ||
{children} | ||
</Board> | ||
</> | ||
); | ||
}; | ||
|
||
export default SettingsLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.