()
| 7 | import {create} from "src/domain/named-queries/handlers" |
| 8 | |
| 9 | export function useTitleForm() { |
| 10 | const active = useSelector(Current.getActiveQuery) |
| 11 | const api = useZuiApi() |
| 12 | const dispatch = useDispatch() |
| 13 | |
| 14 | return { |
| 15 | onSubmit: (e: FormEvent<HTMLFormElement>) => { |
| 16 | e.preventDefault() |
| 17 | const input = e.currentTarget.elements.namedItem("query-name") as any |
| 18 | const name = input.value.trim() || "" |
| 19 | |
| 20 | if (name.length) { |
| 21 | if (active.isSaved() && !active.isModified()) { |
| 22 | api.queries.rename(active.query.id, name) |
| 23 | } else { |
| 24 | create(name) |
| 25 | } |
| 26 | } |
| 27 | dispatch(Layout.hideTitleForm()) |
| 28 | }, |
| 29 | onReset: () => dispatch(Layout.hideTitleForm()), |
| 30 | } |
| 31 | } |
no test coverage detected