Show messages on collection edit, remove and memebership management.

master
Tom Hacohen 4 years ago
parent 1018a4ca90
commit 55507a57f6

@ -22,6 +22,8 @@ import { CachedCollection } from "../Pim/helpers";
import CollectionMemberAddDialog from "./CollectionMemberAddDialog"; import CollectionMemberAddDialog from "./CollectionMemberAddDialog";
import Alert from "@material-ui/lab/Alert"; import Alert from "@material-ui/lab/Alert";
import { pushMessage } from "../store/actions";
import { useDispatch } from "react-redux";
interface PropsType { interface PropsType {
collection: CachedCollection; collection: CachedCollection;
@ -29,10 +31,10 @@ interface PropsType {
export default function CollectionMembers(props: PropsType) { export default function CollectionMembers(props: PropsType) {
const etebase = useCredentials()!; const etebase = useCredentials()!;
const dispatch = useDispatch();
const [members, setMembers] = React.useState<Etebase.CollectionMember[]>(); const [members, setMembers] = React.useState<Etebase.CollectionMember[]>();
const [revokeUser, setRevokeUser] = React.useState<Etebase.CollectionMember | null>(null); const [revokeUser, setRevokeUser] = React.useState<Etebase.CollectionMember | null>(null);
const [addMemberOpen, setAddMemberOpen] = React.useState(false); const [addMemberOpen, setAddMemberOpen] = React.useState(false);
const [inviteSuccessOpen, setInviteSuccessOpen] = React.useState(false);
const [error, setError] = React.useState<Error>(); const [error, setError] = React.useState<Error>();
const { collection, metadata } = props.collection; const { collection, metadata } = props.collection;
@ -71,6 +73,7 @@ export default function CollectionMembers(props: PropsType) {
await memberManager.remove(revokeUser!.username); await memberManager.remove(revokeUser!.username);
await fetchMembers(); await fetchMembers();
setRevokeUser(null); setRevokeUser(null);
dispatch(pushMessage({ message: "Removed member", severity: "success" }));
} }
async function onMemberAdd(username: string, pubkey: Uint8Array, accessLevel: Etebase.CollectionAccessLevel) { async function onMemberAdd(username: string, pubkey: Uint8Array, accessLevel: Etebase.CollectionAccessLevel) {
@ -78,7 +81,7 @@ export default function CollectionMembers(props: PropsType) {
await inviteMgr.invite(collection, username, pubkey, accessLevel); await inviteMgr.invite(collection, username, pubkey, accessLevel);
await fetchMembers(); await fetchMembers();
setAddMemberOpen(false); setAddMemberOpen(false);
setInviteSuccessOpen(true); dispatch(pushMessage({ message: "Invitation sent", severity: "success" }));
} }
return ( return (
@ -149,17 +152,6 @@ export default function CollectionMembers(props: PropsType) {
onClose={() => setAddMemberOpen(false)} onClose={() => setAddMemberOpen(false)}
/> />
} }
<ConfirmationDialog
title="Invite user"
labelOk="OK"
open={inviteSuccessOpen}
onOk={() => setInviteSuccessOpen(false)}
>
<p>
Invitation sent. User will be added once the invitation has been accepted.
</p>
</ConfirmationDialog>
</> </>
); );
} }

@ -19,7 +19,7 @@ import CollectionEdit from "./CollectionEdit";
import CollectionMembers from "./CollectionMembers"; import CollectionMembers from "./CollectionMembers";
import Collection from "./Collection"; import Collection from "./Collection";
import { useAsyncDispatch } from "../store"; import { useAsyncDispatch } from "../store";
import { collectionUpload } from "../store/actions"; import { collectionUpload, pushMessage } from "../store/actions";
import Invitations from "./Invitations"; import Invitations from "./Invitations";
const decryptCollections = getDecryptCollectionsFunction(); const decryptCollections = getDecryptCollectionsFunction();
@ -48,6 +48,7 @@ export default function CollectionsMain() {
async function onSave(collection: Etebase.Collection): Promise<void> { async function onSave(collection: Etebase.Collection): Promise<void> {
const colMgr = getCollectionManager(etebase); const colMgr = getCollectionManager(etebase);
await dispatch(collectionUpload(colMgr, collection)); await dispatch(collectionUpload(colMgr, collection));
dispatch(pushMessage({ message: "Collection saved", severity: "success" }));
history.push(routeResolver.getRoute("collections")); history.push(routeResolver.getRoute("collections"));
} }
@ -59,6 +60,7 @@ export default function CollectionsMain() {
await collection.setMeta({ ...meta, mtime }); await collection.setMeta({ ...meta, mtime });
await collection.delete(true); await collection.delete(true);
await dispatch(collectionUpload(colMgr, collection)); await dispatch(collectionUpload(colMgr, collection));
dispatch(pushMessage({ message: "Collection deleted", severity: "success" }));
history.push(routeResolver.getRoute("collections")); history.push(routeResolver.getRoute("collections"));
} }

Loading…
Cancel
Save