added confirmation on remove/delete

This commit is contained in:
Roland Osborne 2022-06-27 22:51:55 -07:00
parent f6087e7f1e
commit fb345a2a9a
10 changed files with 80 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef } from 'react' import React, { useState, useEffect, useRef } from 'react'
import { CloseOutlined, UserOutlined } from '@ant-design/icons'; import { ExclamationCircleOutlined, CloseOutlined, UserOutlined } from '@ant-design/icons';
import { useContact } from './useContact.hook'; import { useContact } from './useContact.hook';
import { Button, Checkbox, Modal } from 'antd' import { Button, Checkbox, Modal } from 'antd'
import { ContactWrapper, ProfileButton, CloseButton, ContactSpin } from './Contact.styled'; import { ContactWrapper, ProfileButton, CloseButton, ContactSpin } from './Contact.styled';
@ -39,23 +39,53 @@ export function Contact() {
return <span>{ state.description }</span> return <span>{ state.description }</span>
} }
const showDisconnect = () => {
Modal.confirm({
title: 'Do you want to disconnect from this contact?',
icon: <ExclamationCircleOutlined />,
okText: 'Yes, Disconnect',
cancelText: 'No, Cancel',
onOk() { actions.disconnect() },
});
};
const Disconnect = () => { const Disconnect = () => {
if (state.showButtons.disconnect) { if (state.showButtons.disconnect) {
return <ProfileButton ghost onClick={() => actions.disconnect()}>Disconnect</ProfileButton> return <ProfileButton ghost onClick={() => showDisconnect()}>Disconnect</ProfileButton>
} }
return <></> return <></>
} }
const showDisconnectRemove = () => {
Modal.confirm({
title: 'Do you want to remove this contact?',
icon: <ExclamationCircleOutlined />,
okText: 'Yes, Remove',
cancelText: 'No, Cancel',
onOk() { actions.disconnectRemove() },
});
};
const DisconnectRemove = () => { const DisconnectRemove = () => {
if (state.showButtons.disconnectRemove) { if (state.showButtons.disconnectRemove) {
return <ProfileButton ghost onClick={() => actions.disconnectRemove()}>Remove Contact</ProfileButton> return <ProfileButton ghost onClick={() => showDisconnectRemove()}>Remove Contact</ProfileButton>
} }
return <></> return <></>
} }
const showRemove = () => {
Modal.confirm({
title: 'Do you want to remove this contact??',
icon: <ExclamationCircleOutlined />,
okText: 'Yes, Remove',
cancelText: 'No, Cancel',
onOk() { actions.remove() },
});
};
const Remove = () => { const Remove = () => {
if (state.showButtons.remove) { if (state.showButtons.remove) {
return <ProfileButton ghost onClick={() => actions.remove()}>Remove Contact</ProfileButton> return <ProfileButton ghost onClick={() => showRemove()}>Remove Contact</ProfileButton>
} }
return <></> return <></>
} }

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef } from 'react' import React, { useState, useEffect, useRef } from 'react'
import { CloseOutlined, UserOutlined } from '@ant-design/icons'; import { ExclamationCircleOutlined, CloseOutlined, UserOutlined } from '@ant-design/icons';
import { useConversation } from './useConversation.hook'; import { useConversation } from './useConversation.hook';
import { Button, Input, Checkbox, Modal, Spin } from 'antd' import { Button, Input, Checkbox, Modal, Spin } from 'antd'
import { ConversationWrapper, ConversationButton, EditButton, CloseButton, ListItem, BusySpin } from './Conversation.styled'; import { ConversationWrapper, ConversationButton, EditButton, CloseButton, ListItem, BusySpin } from './Conversation.styled';
@ -61,6 +61,16 @@ export function Conversation() {
) )
} }
const showDelete = () => {
Modal.confirm({
title: 'Do you want to delete this conversation?',
icon: <ExclamationCircleOutlined />,
okText: 'Yes, Delete',
cancelText: 'No, Cancel',
onOk() { actions.remove() },
});
};
return ( return (
<ConversationWrapper> <ConversationWrapper>
<div class="header"> <div class="header">
@ -72,7 +82,7 @@ export function Conversation() {
<div class="control"> <div class="control">
<div class="buttons"> <div class="buttons">
<ConversationButton ghost onClick={() => onMembers()}>Members</ConversationButton> <ConversationButton ghost onClick={() => onMembers()}>Members</ConversationButton>
<ConversationButton ghost onClick={() => actions.remove()}>Delete</ConversationButton> <ConversationButton ghost onClick={() => showDelete()}>Delete</ConversationButton>
</div> </div>
<CloseButton type="text" class="close" size={'large'} <CloseButton type="text" class="close" size={'large'}
onClick={() => actions.close()} icon={<CloseOutlined />} /> onClick={() => actions.close()} icon={<CloseOutlined />} />

View File

@ -4,7 +4,6 @@ import { CheckSquareOutlined, BorderOutlined } from '@ant-design/icons';
export const MemberItemWrapper = styled.div` export const MemberItemWrapper = styled.div`
display: flex; display: flex;
width: 100%; width: 100%;
background-color: #f6f5ed;
flex-direction: row; flex-direction: row;
overflow: hidden; overflow: hidden;
padding-left: 16px; padding-left: 16px;

View File

@ -1,5 +1,6 @@
import { useContext, useState, useEffect, useRef } from 'react'; import { useContext, useState, useEffect, useRef } from 'react';
import { CardContext } from 'context/CardContext'; import { CardContext } from 'context/CardContext';
import { ProfileContext } from 'context/ProfileContext';
import { ConversationContext } from 'context/ConversationContext'; import { ConversationContext } from 'context/ConversationContext';
export function useMemberItem({ item }) { export function useMemberItem({ item }) {
@ -12,15 +13,20 @@ export function useMemberItem({ item }) {
}); });
const card = useContext(CardContext); const card = useContext(CardContext);
const profile = useContext(ProfileContext);
const conversation = useContext(ConversationContext); const conversation = useContext(ConversationContext);
useEffect(() => { useEffect(() => {
let handle = item.card?.data.cardProfile.handle;
if (item.card?.data.cardProfile.node != profile.state?.profile.node) {
handle += '@' + item.card?.data.cardProfile.node;
}
updateState({ updateState({
imageUrl: card.actions.getImageUrl(item.card?.id), imageUrl: card.actions.getImageUrl(item.card?.id),
name: item.card?.data.cardProfile.name, name: item.card?.data.cardProfile.name,
handle: item.card?.data.cardProfile.handle, handle,
}); });
}, [item, card]); }, [item, card, profile]);
const updateState = (value) => { const updateState = (value) => {
setState((s) => ({ ...s, ...value })); setState((s) => ({ ...s, ...value }));

View File

@ -3,7 +3,6 @@ import styled from 'styled-components';
export const MembersWrapper = styled.div` export const MembersWrapper = styled.div`
width: 100%; width: 100%;
max-height: 240px; max-height: 240px;
background-color: #f6f5ed;
overflow: auto; overflow: auto;
`; `;

View File

@ -64,8 +64,8 @@ export function Cards({ showRegistry }) {
imageSet={cardProfile(item).imageSet} /> imageSet={cardProfile(item).imageSet} />
</div> </div>
<div class="username"> <div class="username">
<span class="handle">{ cardHandle(item) }</span>
<span class="name">{ cardProfile(item).name }</span> <span class="name">{ cardProfile(item).name }</span>
<span class="handle">{ cardHandle(item) }</span>
</div> </div>
</div> </div>
</CardItem> </CardItem>

View File

@ -11,7 +11,11 @@ export function AddChannel({ state, actions }) {
let contacts = []; let contacts = [];
let cards = actions.getCards(); let cards = actions.getCards();
for (let card of cards) { for (let card of cards) {
contacts.push({ value: card.id, label: card.data.cardProfile.handle }); let handle = card.data.cardProfile.handle;
if (state.node != card.data.cardProfile.node) {
handle += '@' + card.data.cardProfile.node;
}
contacts.push({ value: card.id, label: handle });
} }
setOptions(contacts); setOptions(contacts);
}, [actions]); }, [actions]);

View File

@ -1,6 +1,7 @@
import { useContext, useState, useRef, useEffect } from 'react'; import { useContext, useState, useRef, useEffect } from 'react';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { CardContext } from 'context/CardContext'; import { CardContext } from 'context/CardContext';
import { ProfileContext } from 'context/ProfileContext';
import { ChannelContext } from 'context/ChannelContext'; import { ChannelContext } from 'context/ChannelContext';
export function useChannels() { export function useChannels() {
@ -10,6 +11,7 @@ export function useChannels() {
startCards: [], startCards: [],
startSubject: '', startSubject: '',
startDescription: '', startDescription: '',
node: null,
busy: false, busy: false,
}); });
@ -22,6 +24,7 @@ export function useChannels() {
const navigate = useNavigate(); const navigate = useNavigate();
const card = useContext(CardContext); const card = useContext(CardContext);
const profile = useContext(ProfileContext);
const channel = useContext(ChannelContext); const channel = useContext(ChannelContext);
const actions = { const actions = {
@ -78,6 +81,10 @@ export function useChannels() {
updateState({ channels: merged }); updateState({ channels: merged });
}, [channel]) }, [channel])
useEffect(() => {
updateState({ node: profile.state.profile.node });
}, [profile])
return { state, actions }; return { state, actions };
} }

View File

@ -1,7 +1,7 @@
import { Avatar, Space, Image, Modal, Form, Input, Button } from 'antd'; import { Avatar, Space, Image, Modal, Form, Input, Button } from 'antd';
import React, { useState } from 'react' import React, { useState } from 'react'
import { IdentityWrapper, IdentityDropdown, MenuWrapper } from './Identity.styled'; import { IdentityWrapper, IdentityDropdown, MenuWrapper } from './Identity.styled';
import { RightOutlined, EditOutlined, UserOutlined, LockOutlined } from '@ant-design/icons'; import { ExclamationCircleOutlined, RightOutlined, EditOutlined, UserOutlined, LockOutlined } from '@ant-design/icons';
import { useIdentity } from './useIdentity.hook'; import { useIdentity } from './useIdentity.hook';
import { Menu, Dropdown } from 'antd'; import { Menu, Dropdown } from 'antd';
import { Logo } from '../../../Logo/Logo'; import { Logo } from '../../../Logo/Logo';
@ -10,6 +10,16 @@ export function Identity() {
const { state, actions } = useIdentity() const { state, actions } = useIdentity()
const showLogout = () => {
Modal.confirm({
title: 'Do you want to logout?',
icon: <ExclamationCircleOutlined />,
okText: 'Yes, Logout',
cancelText: 'No, Cancel',
onOk() { actions.logout() },
});
};
const menu = ( const menu = (
<MenuWrapper> <MenuWrapper>
<Menu.Item key="0"> <Menu.Item key="0">
@ -19,7 +29,7 @@ export function Identity() {
<div onClick={() => actions.setShowLogin(true)}>Change Login</div> <div onClick={() => actions.setShowLogin(true)}>Change Login</div>
</Menu.Item> </Menu.Item>
<Menu.Item key="2"> <Menu.Item key="2">
<div onClick={() => actions.logout()}>Sign Out</div> <div onClick={() => showLogout()}>Sign Out</div>
</Menu.Item> </Menu.Item>
</MenuWrapper> </MenuWrapper>
); );

View File

@ -39,9 +39,6 @@ export function useIdentity() {
app.actions.logout(); app.actions.logout();
navigate('/'); navigate('/');
}, },
editLabels: () => {
console.log("EDIT LABELS");
},
editProfile: () => { editProfile: () => {
navigate('/user/profile'); navigate('/user/profile');
}, },