mirror of
1
Fork 0

proper redirect after removing block

This commit is contained in:
f0x 2022-09-18 22:24:41 +02:00
parent 7cebb50e0e
commit 9987399737
3 changed files with 37 additions and 19 deletions

View File

@ -308,19 +308,19 @@ function InstancePageWrapped() {
return adminActions.updateDomainBlockVal([domain, key, val]); return adminActions.updateDomainBlockVal([domain, key, val]);
} }
const fields = formFields(alterDomain, (state) => state.admin.blockedInstances[domain]); const fields = formFields(alterDomain, (state) => state.admin.newInstanceBlocks[domain]);
return <InstancePage domain={domain} Form={fields} />; return <InstancePage domain={domain} Form={fields} />;
} }
function InstancePage({domain, Form}) { function InstancePage({domain, Form}) {
const dispatch = Redux.useDispatch(); const dispatch = Redux.useDispatch();
const { blockedInstances } = Redux.useSelector(state => state.admin); const entry = Redux.useSelector(state => state.admin.newInstanceBlocks[domain]);
const entry = blockedInstances[domain]; const [_location, setLocation] = useLocation();
React.useEffect(() => { React.useEffect(() => {
if (entry == undefined) { if (entry == undefined) {
dispatch(adminActions.newDomainBlock(domain)); dispatch(api.admin.getEditableDomainBlock(domain));
} }
}, []); }, []);
@ -328,12 +328,8 @@ function InstancePage({domain, Form}) {
const [statusMsg, setStatus] = React.useState(""); const [statusMsg, setStatus] = React.useState("");
if (entry == undefined) { if (entry == undefined) {
if (statusMsg == "removed") {
return <Redirect to={base}/>;
} else {
return "Loading..."; return "Loading...";
} }
}
const updateBlock = submit( const updateBlock = submit(
() => dispatch(api.admin.updateDomainBlock(domain)), () => dispatch(api.admin.updateDomainBlock(domain)),
@ -342,7 +338,9 @@ function InstancePage({domain, Form}) {
const removeBlock = submit( const removeBlock = submit(
() => dispatch(api.admin.removeDomainBlock(domain)), () => dispatch(api.admin.removeDomainBlock(domain)),
{setStatus, setError, startStatus: "Removing", successStatus: "Removed!"} {setStatus, setError, startStatus: "Removing", successStatus: "Removed!", onSuccess: () => {
setLocation(base);
}}
); );
return ( return (

View File

@ -57,18 +57,28 @@ module.exports = function ({ apiCall, getChanges }) {
updateDomainBlock: function updateDomainBlock(domain) { updateDomainBlock: function updateDomainBlock(domain) {
return function (dispatch, getState) { return function (dispatch, getState) {
return Promise.try(() => { return Promise.try(() => {
const state = getState().admin.blockedInstances[domain]; const state = getState().admin.newInstanceBlocks[domain];
const update = getChanges(state, { const update = getChanges(state, {
formKeys: ["domain", "obfuscate", "public_comment", "private_comment"], formKeys: ["domain", "obfuscate", "public_comment", "private_comment"],
}); });
return dispatch(apiCall("POST", "/api/v1/admin/domain_blocks", update, "form")); return dispatch(apiCall("POST", "/api/v1/admin/domain_blocks", update, "form"));
}).then((block) => { }).then((block) => {
console.log(block); return Promise.all([
dispatch(admin.newDomainBlock([domain, block])),
dispatch(admin.setDomainBlock([domain, block]))
]);
}); });
}; };
}, },
getEditableDomainBlock: function getEditableDomainBlock(domain) {
return function (dispatch, getState) {
let data = getState().admin.blockedInstances[domain];
return dispatch(admin.newDomainBlock([domain, data]));
};
},
bulkDomainBlock: function bulkDomainBlock() { bulkDomainBlock: function bulkDomainBlock() {
return function (dispatch, getState) { return function (dispatch, getState) {
let invalidDomains = []; let invalidDomains = [];
@ -138,6 +148,8 @@ module.exports = function ({ apiCall, getChanges }) {
return Promise.try(() => { return Promise.try(() => {
const id = getState().admin.blockedInstances[domain].id; const id = getState().admin.blockedInstances[domain].id;
return dispatch(apiCall("DELETE", `/api/v1/admin/domain_blocks/${id}`)); return dispatch(apiCall("DELETE", `/api/v1/admin/domain_blocks/${id}`));
}).then((removed) => {
return dispatch(admin.removeDomainBlock(removed.domain));
}); });
}; };
}, },

View File

@ -51,6 +51,7 @@ module.exports = createSlice({
exportType: "plain", exportType: "plain",
...emptyBlock() ...emptyBlock()
}, },
newInstanceBlocks: {},
emoji: {}, emoji: {},
newEmoji: emptyEmojiForm() newEmoji: emptyEmojiForm()
}, },
@ -63,20 +64,27 @@ module.exports = createSlice({
state.loadedBlockedInstances = true; state.loadedBlockedInstances = true;
}, },
newDomainBlock: (state, { payload: domain }) => { newDomainBlock: (state, { payload: [domain, data] }) => {
state.blockedInstances[domain] = { if (data == undefined) {
domain, data = {
new: true, new: true,
domain,
...emptyBlock() ...emptyBlock()
}; };
}
state.newInstanceBlocks[domain] = data;
}, },
setDomainBlock: (state, { payload: [domain, data = {}] }) => { setDomainBlock: (state, { payload: [domain, data = {}] }) => {
state.blockedInstances[domain] = data; state.blockedInstances[domain] = data;
}, },
removeDomainBlock: (state, {payload: domain}) => {
delete state.blockedInstances[domain];
},
updateDomainBlockVal: (state, { payload: [domain, key, val] }) => { updateDomainBlockVal: (state, { payload: [domain, key, val] }) => {
state.blockedInstances[domain][key] = val; state.newInstanceBlocks[domain][key] = val;
}, },
updateBulkBlockVal: (state, { payload: [key, val] }) => { updateBulkBlockVal: (state, { payload: [key, val] }) => {