-
Notifications
You must be signed in to change notification settings - Fork 63
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
7 changed files
with
86 additions
and
12 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
apps/web/components/kanban-ui/create-new-option-button.tsx
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,13 @@ | ||
import { Button, IconPlus } from '@egodb/ui' | ||
import { useSetAtom } from 'jotai' | ||
import { createNewOptionOpened } from './create-new-option.atom' | ||
|
||
export const CreateNewOptionButton: React.FC = () => { | ||
const setOpened = useSetAtom(createNewOptionOpened) | ||
|
||
return ( | ||
<Button onClick={() => setOpened(true)} w={300} variant="white" leftIcon={<IconPlus />}> | ||
New Stack | ||
</Button> | ||
) | ||
} |
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,55 @@ | ||
import type { ICreateOptionSchema } from '@egodb/core' | ||
import { OptionId } from '@egodb/core' | ||
import { createOptionSchema } from '@egodb/core' | ||
import { Button, Divider, Group, Modal, Stack, TextInput, useForm, zodResolver } from '@egodb/ui' | ||
import { useAtom } from 'jotai' | ||
import { trpc } from '../../trpc' | ||
import type { ITableBaseProps } from '../table/table-base-props' | ||
import { createNewOptionOpened } from './create-new-option.atom' | ||
|
||
export const CreateNewOptionModal: React.FC<ITableBaseProps> = ({ table }) => { | ||
const [opened, setOpened] = useAtom(createNewOptionOpened) | ||
const form = useForm<ICreateOptionSchema>({ | ||
initialValues: { | ||
name: '', | ||
}, | ||
validate: zodResolver(createOptionSchema), | ||
}) | ||
|
||
const utils = trpc.useContext() | ||
|
||
const createOption = trpc.table.createOption.useMutation({ | ||
onSuccess() { | ||
setOpened(false) | ||
form.reset() | ||
utils.table.get.refetch() | ||
}, | ||
}) | ||
|
||
const onSubmit = form.onSubmit((values) => { | ||
values.id = OptionId.create().value | ||
createOption.mutate({ | ||
tableId: table.id.value, | ||
option: values, | ||
}) | ||
}) | ||
|
||
return ( | ||
<Modal title="Create New Option" opened={opened} onClose={() => setOpened(false)}> | ||
<form onSubmit={onSubmit}> | ||
<Stack> | ||
<TextInput placeholder="option name" {...form.getInputProps('name')} /> | ||
<Divider /> | ||
<Group position="right"> | ||
<Button variant="white" onClick={() => setOpened(false)}> | ||
Cancel | ||
</Button> | ||
<Button type="submit" disabled={!form.isValid()}> | ||
Done | ||
</Button> | ||
</Group> | ||
</Stack> | ||
</form> | ||
</Modal> | ||
) | ||
} |
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,3 @@ | ||
import { atom } from 'jotai' | ||
|
||
export const createNewOptionOpened = atom(false) |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export { Button, UnstyledButton, ActionIcon, ActionIconProps } from '@mantine/core' | ||
export { Button, UnstyledButton, ActionIcon } from '@mantine/core' |