mirror of
https://github.com/umami-software/umami.git
synced 2026-02-23 22:15:35 +01:00
Converted mutation queries.
This commit is contained in:
parent
3f167e05ba
commit
0f9669f886
34 changed files with 259 additions and 350 deletions
|
|
@ -3,7 +3,7 @@ import { ActionButton } from '@/components/input/ActionButton';
|
|||
import { Trash } from '@/components/icons';
|
||||
import { ConfirmationForm } from '@/components/common/ConfirmationForm';
|
||||
import { messages } from '@/components/messages';
|
||||
import { useApi, useMessages, useModified } from '@/components/hooks';
|
||||
import { useDeleteQuery, useMessages } from '@/components/hooks';
|
||||
|
||||
export function CohortDeleteButton({
|
||||
cohortId,
|
||||
|
|
@ -17,11 +17,9 @@ export function CohortDeleteButton({
|
|||
onSave?: () => void;
|
||||
}) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { del, useMutation } = useApi();
|
||||
const { mutate, isPending, error } = useMutation({
|
||||
mutationFn: () => del(`/websites/${websiteId}/segments/${cohortId}`),
|
||||
});
|
||||
const { touch } = useModified();
|
||||
const { mutate, isPending, error, touch } = useDeleteQuery(
|
||||
`/websites/${websiteId}/segments/${cohortId}`,
|
||||
);
|
||||
|
||||
const handleConfirm = (close: () => void) => {
|
||||
mutate(null, {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import {
|
|||
import { subMonths, endOfDay } from 'date-fns';
|
||||
import { FieldFilters } from '@/components/input/FieldFilters';
|
||||
import { useState } from 'react';
|
||||
import { useApi, useMessages, useModified, useWebsiteCohortQuery } from '@/components/hooks';
|
||||
import { useMessages, useUpdateQuery, useWebsiteCohortQuery } from '@/components/hooks';
|
||||
import { filtersArrayToObject } from '@/lib/params';
|
||||
|
||||
export function CohortEditForm({
|
||||
|
|
@ -30,26 +30,25 @@ export function CohortEditForm({
|
|||
onClose?: () => void;
|
||||
}) {
|
||||
const { data } = useWebsiteCohortQuery(websiteId, cohortId);
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const [currentFilters, setCurrentFilters] = useState(filters);
|
||||
const { touch } = useModified();
|
||||
const startDate = subMonths(endOfDay(new Date()), 6);
|
||||
const endDate = endOfDay(new Date());
|
||||
|
||||
const { post, useMutation } = useApi();
|
||||
const { mutate, error, isPending } = useMutation({
|
||||
mutationFn: (data: any) =>
|
||||
post(`/websites/${websiteId}/cohorts${cohortId ? `/${cohortId}` : ''}`, {
|
||||
...data,
|
||||
type: 'cohort',
|
||||
}),
|
||||
});
|
||||
const { mutate, error, isPending, touch, toast } = useUpdateQuery(
|
||||
`/websites/${websiteId}/cohorts${cohortId ? `/${cohortId}` : ''}`,
|
||||
{
|
||||
...data,
|
||||
type: 'cohort',
|
||||
},
|
||||
);
|
||||
|
||||
const handleSubmit = async (data: any) => {
|
||||
mutate(
|
||||
{ ...data, parameters: filtersArrayToObject(currentFilters) },
|
||||
{
|
||||
onSuccess: async () => {
|
||||
toast(formatMessage(messages.save));
|
||||
touch('cohorts');
|
||||
onSave?.();
|
||||
onClose?.();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue