-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fetch, create, delete custom filters
- Loading branch information
1 parent
a0dcad2
commit 1b9182c
Showing
22 changed files
with
420 additions
and
5 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
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
6 changes: 6 additions & 0 deletions
6
src/components/FilterCreateForm/FilterCreateForm.i18n/en.json
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,6 @@ | ||
{ | ||
"Title": "", | ||
"Description": "", | ||
"Create filter": "", | ||
"New filters preset": "" | ||
} |
17 changes: 17 additions & 0 deletions
17
src/components/FilterCreateForm/FilterCreateForm.i18n/index.ts
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,17 @@ | ||
/* eslint-disable */ | ||
// Do not edit, use generator to update | ||
import { i18n, fmt, I18nLangSet } from 'easy-typed-intl'; | ||
import getLang from '../../../i18n/getLang'; | ||
|
||
import ru from './ru.json'; | ||
import en from './en.json'; | ||
|
||
type I18nKey = keyof typeof ru & keyof typeof en; | ||
type I18nLang = 'ru' | 'en'; | ||
|
||
const keyset: I18nLangSet<I18nKey> = {}; | ||
|
||
keyset['ru'] = ru; | ||
keyset['en'] = en; | ||
|
||
export const tr = i18n<I18nLang, I18nKey>(keyset, fmt, getLang); |
6 changes: 6 additions & 0 deletions
6
src/components/FilterCreateForm/FilterCreateForm.i18n/ru.json
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,6 @@ | ||
{ | ||
"Title": "", | ||
"Description": "", | ||
"Create filter": "", | ||
"New filters preset": "" | ||
} |
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,106 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { | ||
Button, | ||
Form, | ||
FormActions, | ||
FormAction, | ||
FormTextarea, | ||
FormInput, | ||
FormTitle, | ||
ModalHeader, | ||
ModalContent, | ||
} from '@taskany/bricks'; | ||
|
||
import { submitKeys } from '../../utils/hotkeys'; | ||
import { errorsProvider } from '../../utils/forms'; | ||
import { CreateFormType, createSchema } from '../../schema/filter'; | ||
import { Filter, FilterCreateInput } from '../../../graphql/@generated/genql'; | ||
import { useFilterResource } from '../../hooks/useFilterResource'; | ||
import { Void } from '../../types/void'; | ||
|
||
import { tr } from './FilterCreateForm.i18n'; | ||
|
||
interface FilterCreateFormProps { | ||
mode: FilterCreateInput['mode']; | ||
params: FilterCreateInput['params']; | ||
|
||
onSubmit?: Void<Partial<Filter>>; | ||
} | ||
|
||
const FilterCreateForm: React.FC<FilterCreateFormProps> = ({ mode, params, onSubmit }) => { | ||
const { createFilter } = useFilterResource(); | ||
// const [formBusy, setFormBusy] = useState(false); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isValid, isSubmitted }, | ||
} = useForm<CreateFormType>({ | ||
resolver: zodResolver(createSchema), | ||
mode: 'onChange', | ||
reValidateMode: 'onChange', | ||
shouldFocusError: true, | ||
defaultValues: { | ||
mode, | ||
params, | ||
}, | ||
}); | ||
|
||
const errorsResolver = errorsProvider(errors, isSubmitted); | ||
|
||
const onPending = useCallback( | ||
async (form: CreateFormType) => { | ||
// setFormBusy(true); | ||
|
||
const [data, err] = await createFilter(form); | ||
|
||
if (data && data.createFilter && !err) { | ||
onSubmit?.(data.createFilter); | ||
} | ||
}, | ||
[createFilter, onSubmit], | ||
); | ||
|
||
const onError = useCallback((err: typeof errors) => { | ||
// TODO: Sentry event | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<ModalHeader> | ||
<FormTitle>{tr('New filters preset')}</FormTitle> | ||
</ModalHeader> | ||
|
||
<ModalContent> | ||
{/* TODO: pass disabled via formBusy */} | ||
<Form submitHotkey={submitKeys} onSubmit={handleSubmit(onPending, onError)}> | ||
<FormInput | ||
{...register('title')} | ||
placeholder={tr('Title')} | ||
flat="bottom" | ||
brick="right" | ||
error={errorsResolver('title')} | ||
/> | ||
|
||
<FormTextarea | ||
{...register('description')} | ||
placeholder={tr('Description')} | ||
flat="both" | ||
error={errorsResolver('description')} | ||
/> | ||
|
||
<FormActions flat="top"> | ||
<FormAction left inline /> | ||
<FormAction right inline> | ||
<Button view="primary" outline={!isValid} type="submit" text={tr('Create filter')} /> | ||
</FormAction> | ||
</FormActions> | ||
</Form> | ||
</ModalContent> | ||
</> | ||
); | ||
}; | ||
|
||
export default FilterCreateForm; |
6 changes: 6 additions & 0 deletions
6
src/components/FilterDeleteForm/FilterDeleteForm.i18n/en.json
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,6 @@ | ||
{ | ||
"You are trying to delete filters preset": "You are trying to delete filters preset", | ||
"Are you sure to delete filters preset {preset}?": "Are you sure to delete filters preset {preset}?", | ||
"Cancel": "Cancel", | ||
"Yes, delete it": "Yes, delete it" | ||
} |
17 changes: 17 additions & 0 deletions
17
src/components/FilterDeleteForm/FilterDeleteForm.i18n/index.ts
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,17 @@ | ||
/* eslint-disable */ | ||
// Do not edit, use generator to update | ||
import { i18n, fmt, I18nLangSet } from 'easy-typed-intl'; | ||
import getLang from '../../../i18n/getLang'; | ||
|
||
import ru from './ru.json'; | ||
import en from './en.json'; | ||
|
||
type I18nKey = keyof typeof ru & keyof typeof en; | ||
type I18nLang = 'ru' | 'en'; | ||
|
||
const keyset: I18nLangSet<I18nKey> = {}; | ||
|
||
keyset['ru'] = ru; | ||
keyset['en'] = en; | ||
|
||
export const tr = i18n<I18nLang, I18nKey>(keyset, fmt, getLang); |
6 changes: 6 additions & 0 deletions
6
src/components/FilterDeleteForm/FilterDeleteForm.i18n/ru.json
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,6 @@ | ||
{ | ||
"You are trying to delete filters preset": "Ты собираешься удалить пресет с фильтрами", | ||
"Are you sure to delete filters preset {preset}?": "Уверен, что хочешь удалить пересет {preset}?", | ||
"Cancel": "Отмена", | ||
"Yes, delete it": "Да, удаляем" | ||
} |
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,62 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import { Button, Form, FormAction, FormActions, FormTitle, ModalContent, ModalHeader, Text } from '@taskany/bricks'; | ||
import { warn0 } from '@taskany/colors'; | ||
|
||
import { Filter } from '../../../graphql/@generated/genql'; | ||
import { useFilterResource } from '../../hooks/useFilterResource'; | ||
|
||
import { tr } from './FilterDeleteForm.i18n'; | ||
|
||
interface FilterDeleteFormProps { | ||
preset: Filter; | ||
|
||
onSubmit: (preset: Filter) => void; | ||
onCancel: () => void; | ||
} | ||
|
||
const FilterDeleteForm: React.FC<FilterDeleteFormProps> = ({ preset, onSubmit, onCancel }) => { | ||
const { deleteFilter } = useFilterResource(); | ||
|
||
const onSubmitProvider = useCallback( | ||
(preset: Filter) => async () => { | ||
const [data, err] = await deleteFilter({ id: preset.id }); | ||
|
||
if (data && data.deleteFilter && !err) { | ||
onSubmit(preset); | ||
} | ||
}, | ||
[onSubmit, deleteFilter], | ||
); | ||
|
||
const onSubmitClick = useMemo(() => onSubmitProvider(preset), [onSubmitProvider, preset]); | ||
|
||
return ( | ||
<> | ||
<ModalHeader> | ||
<FormTitle color={warn0}>{tr('You are trying to delete filters preset')}</FormTitle> | ||
</ModalHeader> | ||
|
||
<ModalContent> | ||
<Text> | ||
{tr.raw('Are you sure to delete filters preset {preset}?', { | ||
preset: <b key={preset.title}>{preset.title}</b>, | ||
})} | ||
</Text> | ||
|
||
<br /> | ||
|
||
<Form> | ||
<FormActions flat="top"> | ||
<FormAction left /> | ||
<FormAction right inline> | ||
<Button size="m" text={tr('Cancel')} onClick={onCancel} /> | ||
<Button size="m" view="warning" onClick={onSubmitClick} text={tr('Yes, delete it')} /> | ||
</FormAction> | ||
</FormActions> | ||
</Form> | ||
</ModalContent> | ||
</> | ||
); | ||
}; | ||
|
||
export default FilterDeleteForm; |
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,5 +1,7 @@ | ||
{ | ||
"We are saving your filter...": "We are saving your filter...", | ||
"Voila! Saved successfully 🎉! Use and share it with teammates 😉": "Voila! Saved successfully 🎉! Use and share it with teammates 😉", | ||
"Something went wrong 😿": "Something went wrong 😿" | ||
"Something went wrong 😿": "Something went wrong 😿", | ||
"We are deleting your filter...": "We are deleting your filter...", | ||
"Deleted successfully 🎉!": "Deleted successfully 🎉!" | ||
} |
Oops, something went wrong.