Commit af6f75cd authored by tom goriunov's avatar tom goriunov Committed by GitHub

Merge pull request #7 from tom2drum/edit-address

модал редактирования адреса
parents 176057fc aebfae0e
import React from 'react'; import React, { useCallback, useState } from 'react';
import { import {
Box, Box,
...@@ -17,14 +17,33 @@ import { ...@@ -17,14 +17,33 @@ import {
GridItem, GridItem,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import type { TWatchlistItem } from '../../data/watchlist';
const NOTIFICATIONS = [ 'xDAI', 'ERC-20', 'ERC-721, ERC-1155 (NFT)' ]; const NOTIFICATIONS = [ 'xDAI', 'ERC-20', 'ERC-721, ERC-1155 (NFT)' ];
type Props = { type Props = {
isOpen: boolean; isOpen: boolean;
onClose: () => void; onClose: () => void;
getDisclosureProps: () => any;
data?: TWatchlistItem;
} }
const AddAddressModal: React.FC<Props> = ({ isOpen, onClose }) => { const AddressModal: React.FC<Props> = ({ isOpen, onClose, data = {} as TWatchlistItem }) => {
// надо чето придумать с формой
// потом доделаем
const [ address, setAddress ] = useState(data.address);
const [ tag, setTag ] = useState(data.tag);
const [ notification, setNotification ] = useState(data.notification);
const onAddressChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => setAddress(event.target.value), [ setAddress ]);
const onTagChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => setTag(event.target.value), [ setTag ]);
const onNotificationChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => setNotification(event.target.checked), [ setNotification ]);
const onButtonClick = useCallback(() => {
// eslint-disable-next-line no-console
console.log(address, tag, notification);
onClose()
}, [ address, tag, notification, onClose ]);
return ( return (
<Modal isOpen={ isOpen } onClose={ onClose } size="md"> <Modal isOpen={ isOpen } onClose={ onClose } size="md">
<ModalOverlay/> <ModalOverlay/>
...@@ -35,8 +54,18 @@ const AddAddressModal: React.FC<Props> = ({ isOpen, onClose }) => { ...@@ -35,8 +54,18 @@ const AddAddressModal: React.FC<Props> = ({ isOpen, onClose }) => {
<Text lineHeight="30px" marginBottom="40px"> <Text lineHeight="30px" marginBottom="40px">
An Email notification can be sent to you when an address on your watch list sends or receives any transactions. An Email notification can be sent to you when an address on your watch list sends or receives any transactions.
</Text> </Text>
<Input placeholder="Address (0x...)*" marginBottom="20px"/> <Input
<Input placeholder="Private tag (max 35 characters)*" marginBottom="30px"/> placeholder="Address (0x...)*"
marginBottom="20px"
onChange={ onAddressChange }
value={ address }
/>
<Input
placeholder="Private tag (max 35 characters)*"
marginBottom="30px"
onChange={ onTagChange }
value={ tag }
/>
<Text color="gray.600" fontSize="14px" marginBottom="32px"> <Text color="gray.600" fontSize="14px" marginBottom="32px">
Please select what types of notifications you will receive: Please select what types of notifications you will receive:
</Text> </Text>
...@@ -54,11 +83,17 @@ const AddAddressModal: React.FC<Props> = ({ isOpen, onClose }) => { ...@@ -54,11 +83,17 @@ const AddAddressModal: React.FC<Props> = ({ isOpen, onClose }) => {
</Grid> </Grid>
</Box> </Box>
<Text color="gray.600" fontSize="14px" marginBottom="20px">Notification methods:</Text> <Text color="gray.600" fontSize="14px" marginBottom="20px">Notification methods:</Text>
<Checkbox defaultChecked colorScheme="green">Email notifications</Checkbox> <Checkbox
defaultChecked={ notification }
colorScheme="green"
onChange={ onNotificationChange }
>
Email notifications
</Checkbox>
</ModalBody> </ModalBody>
<ModalFooter justifyContent="flex-start"> <ModalFooter justifyContent="flex-start">
<Button colorScheme="blue" onClick={ onClose }> <Button colorScheme="blue" onClick={ onButtonClick }>
Add address Add address
</Button> </Button>
</ModalFooter> </ModalFooter>
...@@ -67,4 +102,4 @@ const AddAddressModal: React.FC<Props> = ({ isOpen, onClose }) => { ...@@ -67,4 +102,4 @@ const AddAddressModal: React.FC<Props> = ({ isOpen, onClose }) => {
) )
} }
export default AddAddressModal; export default AddressModal;
import React from 'react';
import {
Tag,
Tr,
Td,
Switch,
Icon,
HStack,
useDisclosure,
} from '@chakra-ui/react'
import { FaEdit, FaTrash } from 'react-icons/fa';
import type { TWatchlistItem } from '../../data/watchlist';
import AddressModal from '../AddressModal/AddressModal';
import WatchListAddressItem from './WatchListAddressItem';
interface Props {
item: TWatchlistItem;
}
const WatchlistTableItem = ({ item }: Props) => {
const modalProps = useDisclosure();
return (
<>
<Tr alignItems="top" key={ item.address }>
<Td><WatchListAddressItem item={ item }/></Td>
<Td><Tag>{ item.tag }</Tag></Td>
<Td><Switch colorScheme="green" size="md" isChecked={ item.notification }/></Td>
<Td>
<HStack spacing="30px">
<Icon as={ FaEdit } w="20px" h="20px" cursor="pointer" color="blue.500" onClick={ modalProps.onOpen }/>
<Icon as={ FaTrash } w="20px" h="20px" cursor="pointer" color="red.200"/>
</HStack>
</Td>
</Tr>
<AddressModal { ...modalProps } data={ item }/>
</>
)
};
export default WatchlistTableItem;
import React from 'react'; import React from 'react';
import { import {
Tag,
Table, Table,
Thead, Thead,
Tbody, Tbody,
Tr, Tr,
Th, Th,
Td,
TableContainer, TableContainer,
Switch,
Icon,
HStack,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { FaEdit, FaTrash } from 'react-icons/fa';
import type { TWatchlist } from '../../data/watchlist'; import type { TWatchlist } from '../../data/watchlist';
import WatchListAddressItem from './WatchListAddressItem'; import WatchlistTableItem from './WatchListTableItem';
interface Props { interface Props {
data: TWatchlist; data: TWatchlist;
...@@ -36,21 +30,7 @@ const WatchlistTable = ({ data }: Props) => { ...@@ -36,21 +30,7 @@ const WatchlistTable = ({ data }: Props) => {
</Tr> </Tr>
</Thead> </Thead>
<Tbody> <Tbody>
{ data.map(item => { { data.map(item => <WatchlistTableItem item={ item } key={ item.address }/>) }
return (
<Tr alignItems="top" key={ item.address }>
<Td><WatchListAddressItem item={ item }/></Td>
<Td><Tag>{ item.tag }</Tag></Td>
<Td><Switch colorScheme="green" size="md" isChecked={ item.notification }/></Td>
<Td>
<HStack spacing="30px">
<Icon as={ FaEdit } w="20px" h="20px" cursor="pointer" color="blue.500"/>
<Icon as={ FaTrash } w="20px" h="20px" cursor="pointer" color="red.200"/>
</HStack>
</Td>
</Tr>
)
}) }
</Tbody> </Tbody>
</Table> </Table>
</TableContainer> </TableContainer>
......
...@@ -6,12 +6,12 @@ import { Box, Button, Text, useDisclosure } from '@chakra-ui/react'; ...@@ -6,12 +6,12 @@ import { Box, Button, Text, useDisclosure } from '@chakra-ui/react';
import Page from '../components/Page/Page'; import Page from '../components/Page/Page';
import WatchlistTable from '../components/WatchlistTable/WatchlistTable'; import WatchlistTable from '../components/WatchlistTable/WatchlistTable';
import AddAddressModal from '../components/AddAddressModal/AddAddressModal'; import AddressModal from '../components/AddressModal/AddressModal';
import { watchlist } from '../data/watchlist'; import { watchlist } from '../data/watchlist';
const WatchList: NextPage = () => { const WatchList: NextPage = () => {
const addModalProps = useDisclosure() const addressModalProps = useDisclosure();
return ( return (
<Page> <Page>
<Box h="100%"> <Box h="100%">
...@@ -20,13 +20,13 @@ const WatchList: NextPage = () => { ...@@ -20,13 +20,13 @@ const WatchList: NextPage = () => {
<Box marginTop="32px"> <Box marginTop="32px">
<Button <Button
colorScheme="blue" colorScheme="blue"
onClick={ addModalProps.onOpen } onClick={ addressModalProps.onOpen }
> >
Add address Add address
</Button> </Button>
</Box> </Box>
</Box> </Box>
<AddAddressModal { ...addModalProps }/> <AddressModal { ...addressModalProps }/>
</Page> </Page>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment