pl-fe: migrate account actions to tanstack query
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
import { muteAccount } from 'pl-fe/actions/accounts';
|
||||
import { useAccount } from 'pl-fe/api/hooks/accounts/use-account';
|
||||
import HStack from 'pl-fe/components/ui/hstack';
|
||||
import Modal from 'pl-fe/components/ui/modal';
|
||||
@ -9,8 +8,8 @@ import Stack from 'pl-fe/components/ui/stack';
|
||||
import Text from 'pl-fe/components/ui/text';
|
||||
import Toggle from 'pl-fe/components/ui/toggle';
|
||||
import DurationSelector from 'pl-fe/features/compose/components/polls/duration-selector';
|
||||
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
||||
import { useFeatures } from 'pl-fe/hooks/use-features';
|
||||
import { useMuteAccountMutation } from 'pl-fe/queries/accounts/use-relationship';
|
||||
|
||||
import type { BaseModalProps } from 'pl-fe/features/ui/components/modal-root';
|
||||
|
||||
@ -19,21 +18,23 @@ interface MuteModalProps {
|
||||
}
|
||||
|
||||
const MuteModal: React.FC<MuteModalProps & BaseModalProps> = ({ accountId, onClose }) => {
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const { account } = useAccount(accountId || undefined);
|
||||
const [notifications, setNotifications] = useState(true);
|
||||
const [duration, setDuration] = useState(0);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const mutesDuration = useFeatures().mutesDuration;
|
||||
|
||||
const { mutate: muteAccount } = useMuteAccountMutation(accountId);
|
||||
|
||||
if (!account) return null;
|
||||
|
||||
const handleClick = () => {
|
||||
setIsSubmitting(true);
|
||||
dispatch(muteAccount(account.id, notifications, duration))?.then(() => {
|
||||
setIsSubmitting(false);
|
||||
onClose('MUTE');
|
||||
muteAccount({ notifications, duration }, {
|
||||
onSuccess: () => {
|
||||
setIsSubmitting(false);
|
||||
onClose('MUTE');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||
|
||||
import { blockAccount } from 'pl-fe/actions/accounts';
|
||||
import { submitReport, ReportableEntities } from 'pl-fe/actions/reports';
|
||||
import { fetchAccountTimeline } from 'pl-fe/actions/timelines';
|
||||
import { useAccount } from 'pl-fe/api/hooks/accounts/use-account';
|
||||
@ -15,6 +14,7 @@ import AccountContainer from 'pl-fe/containers/account-container';
|
||||
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
||||
import { useAppSelector } from 'pl-fe/hooks/use-app-selector';
|
||||
import { useInstance } from 'pl-fe/hooks/use-instance';
|
||||
import { useBlockAccountMutation } from 'pl-fe/queries/accounts/use-relationship';
|
||||
|
||||
import ConfirmationStep from './steps/confirmation-step';
|
||||
import OtherActionsStep from './steps/other-actions-step';
|
||||
@ -81,6 +81,8 @@ const ReportModal: React.FC<BaseModalProps & ReportModalProps> = ({ onClose, acc
|
||||
|
||||
const { account } = useAccount(accountId || undefined);
|
||||
|
||||
const { mutate: blockAccount } = useBlockAccountMutation(accountId);
|
||||
|
||||
const [block, setBlock] = useState(false);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const { rules } = useInstance();
|
||||
@ -109,7 +111,7 @@ const ReportModal: React.FC<BaseModalProps & ReportModalProps> = ({ onClose, acc
|
||||
});
|
||||
|
||||
if (block && account) {
|
||||
dispatch(blockAccount(account.id));
|
||||
blockAccount();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user