Skip to content

Commit

Permalink
Merge pull request #19 from damla/dev
Browse files Browse the repository at this point in the history
[#3, #4] Addition of Language Selector and Edits on Dashboard
  • Loading branch information
damla authored Apr 22, 2022
2 parents e0a8f09 + 3d8d94d commit 5e3a7fa
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 78 deletions.
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
reactStrictMode: false,
i18n: {
// These are all the locales you want to support in
// your application
Expand All @@ -10,7 +10,7 @@ const nextConfig = {
defaultLocale: 'en',
},
images: {
domains: ['images.unsplash.com'],
domains: ['images.unsplash.com', 'avatars.githubusercontent.com'],
},
};

Expand Down
1 change: 0 additions & 1 deletion src/components/common/ConnectWallet/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const ConnectWallet = ({ icon, defaultText }: Props) => {
})
.catch(function (err) {
console.log(err);
// TODO: error notification for non-wallet users
addError(err);
});
}
Expand Down
18 changes: 18 additions & 0 deletions src/components/common/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum Icons {
TWITTER = 'twitter',
METAMASK = 'metamask',
ETHEREUM = 'ethereum',
ETHEREUM_WHITE = 'ethereumWhite',
}

const icons = {
Expand Down Expand Up @@ -470,6 +471,23 @@ const icons = {
></path>
</svg>
),
ethereumWhite: (
<svg
className="w-5 h-5 mr-2 -ml-1 text-white"
aria-hidden="true"
focusable="false"
data-prefix="fab"
data-icon="ethereum"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 320 512"
>
<path
fill="currentColor"
d="M311.9 260.8L160 353.6 8 260.8 160 0l151.9 260.8zM160 383.4L8 290.6 160 512l152-221.4-152 92.8z"
></path>
</svg>
),
};

type Props = {
Expand Down
55 changes: 55 additions & 0 deletions src/components/common/LanguageSelector/LanguageSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Menu, Transition } from '@headlessui/react';
import { ChevronUpIcon } from '@heroicons/react/solid';
import Link from 'next/link';
import { Fragment } from 'react';

const LanguageSelector = () => {
// const [selectedLang, setSelectedLang] = useState([
// { value: 'en', label: 'English', current: true },
// { value: 'tr', label: 'Turkish', current: false },
// ]);

return (
<div className="w-28 text-left">
<Menu as="div" className="relative inline-block text-left">
<Menu.Button className="inline-flex justify-center w-full px-4 py-2 text-sm font-medium text-white bg-black rounded-md bg-opacity-20 hover:bg-opacity-30 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75">
Languages
<ChevronUpIcon
className="w-5 h-5 ml-2 -mr-1 text-cyan-100 hover:text-cyan-100"
aria-hidden="true"
/>
</Menu.Button>
<Transition
as={Fragment}
enter="transition ease-out duration-50"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-50"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items className="absolute left-0 bottom-10 w-32 mt-2 origin-top-right bg-white divide-y divide-gray-100 rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
<div className="px-1 py-1">
<Menu.Item>
<Link href="/" locale="en">
<a className="font-bold hover:bg-cyan-500 active:bg-cyan-500 hover:text-white text-gray-900 group flex rounded-md items-center w-full px-2 py-2 text-sm">
🇬🇧 EN
</a>
</Link>
</Menu.Item>
<Menu.Item>
<Link href="/" locale="tr">
<a className="font-bold hover:bg-cyan-500 hover:text-white text-gray-900 group flex rounded-md items-center w-full px-2 py-2 text-sm">
🇹🇷 TR
</a>
</Link>
</Menu.Item>
</div>
</Menu.Items>
</Transition>
</Menu>
</div>
);
};

export default LanguageSelector;
7 changes: 4 additions & 3 deletions src/components/common/Notification/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const Notification = () => {
return (
<div
id="toast-warning"
className={`absolute transition-transform ease-out scale-0 duration-500 right-5 top-5 items-center shadow-md w-full max-w-xs p-4 text-gray-500 bg-slate-100 rounded-lg dark:text-gray-400 dark:bg-gray-800 ${
isVisible &&
classNames('flex transition-all ease-in scale-100 duration-500')
className={`absolute flex right-5 top-5 items-center shadow-md w-full max-w-xs p-4 text-gray-500 bg-slate-100 rounded-lg dark:text-gray-400 dark:bg-gray-800 ${
isVisible
? classNames('transition-all ease-in scale-100 duration-300')
: 'transition-transform ease-out scale-0 duration-300'
}`}
role="alert"
>
Expand Down
1 change: 1 addition & 0 deletions src/components/common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as Icon } from './Icon/Icon';
export { default as Spinner } from './Spinner/Spinner';
export { default as ConnectWallet } from './ConnectWallet/ConnectWallet';
export { default as Notification } from './Notification/Notification';
export { default as LanguageSelector } from './LanguageSelector/LanguageSelector';
8 changes: 5 additions & 3 deletions src/components/layouts/Dashboard/DashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const Dashboardlayout = ({ children, title }: Props) => (
content="ConnEth dashboard for using utilities"
/>
</Head>
<div className="min-h-full">
<Nav />
<Header title={title} />
<div className="min-h-screen flex flex-col justify-between">
<div>
<Nav />
<Header title={title} />
</div>
<Main>{children}</Main>
<Footer />
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/components/layouts/Dashboard/modules/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Link from 'next/link';
import { APP_NAME } from '../../../../../utils/constants';
import Icon, { Icons } from '../../../../common/Icon/Icon';

const Footer = () => (
<footer className="p-4 bg-white shadow md:px-6 md:py-8 dark:bg-gray-800">
<div className="sm:flex sm:items-center sm:justify-between">
<ul className="flex items-center mb-6 text-sm sm:mb-0">
<Link href="/">
<a className="text-xl font-semibold whitespace-nowrap dark:text-white">
<a className="hover:cursor-pointer inline-flex sm:mb-0 text-gray-800 hover:opacity-80 text-xl font-bold items-center">
<Icon icon={Icons.ETHEREUM} alt="ethereum" />
{APP_NAME}
</a>
</Link>
Expand Down
84 changes: 37 additions & 47 deletions src/components/layouts/Dashboard/modules/Nav/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Disclosure } from '@headlessui/react';
import { MenuIcon, XIcon } from '@heroicons/react/outline';
import Image from 'next/image';
import { LogoutIcon, MenuIcon, XIcon } from '@heroicons/react/outline';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { useMoralis } from 'react-moralis';
import { APP_NAME } from '../../../../../utils/constants';
import { getEllipsesText } from '../../../../../utils/utils';
import { Icon } from '../../../../common';
import { Icons } from '../../../../common/Icon/Icon';

const Nav = () => {
const { isAuthenticated, logout, user } = useMoralis();
Expand All @@ -16,27 +19,28 @@ const Nav = () => {
{ name: '💰 Balance', href: '#' },
];

const userNavigation = [
// { name: 'Your Profile', href: '#' },
{ name: user && getEllipsesText(user?.get('ethAddress')), href: '#' },
{ name: 'Sign out', href: '#' },
];
// const userNavigation = [
// // { name: 'Your Profile', href: '#' },
// { name: user && getEllipsesText(user?.get('ethAddress')), href: '#' },
// { name: 'Sign out', href: '#' },
// ];

useEffect(() => {
if (!isAuthenticated) router.replace('/');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isAuthenticated]);

return (
<Disclosure as="nav" className="bg-gray-800">
<Disclosure as="nav" className="bg-gradient-to-r from-cyan-500 to-blue-500">
{({ open }) => (
<>
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16">
<div className="flex items-center">
<div className="flex-shrink-0">
<Link href="/">
<a className="hover:cursor-pointer hover:text-gray-300 text-white text-xl font-bold">
<a className="hover:cursor-pointer inline-flex sm:mb-0 text-white hover:opacity-80 text-xl font-bold items-center">
<Icon icon={Icons.ETHEREUM_WHITE} alt="ethereum" />
{APP_NAME}
</a>
</Link>
Expand All @@ -47,7 +51,7 @@ const Nav = () => {
<a
key={item.name}
href={item.href}
className="text-white hover:bg-gray-700 hover:text-gray px-3 py-2 rounded-md text-sm font-medium"
className="text-white hover:bg-blue-500 hover:text-gray px-3 py-2 rounded-md text-sm font-medium"
>
{item.name}
</a>
Expand All @@ -59,38 +63,31 @@ const Nav = () => {
<div className="ml-4 flex items-center md:ml-6"></div>
<div className="flex">
{user && (
<>
<div className="flex text-white hover:bg-gray-700 hover:text-gray px-3 py-2 rounded-md items-center hover:cursor-default">
{/* <Avatar
isRounded
avatarKey={Math.floor(Math.random() * 100)}
text={user?.get('ethAddress').slice(0, 2)}
theme="letters"
/> */}
<div className="flex flex-col justify-end">
<span
onClick={logout}
className="px-4 text-base font-medium inline-flex items-center"
>
{getEllipsesText(user?.get('ethAddress'))}
</span>
{/* <PopoverElement
icon="logOut"
iconColor="white"
onClick={logout}
text="Logout"
textSize={13}
textColor="white"
/> */}
</div>
<button
type="button"
onClick={logout}
className="flex text-white hover:bg-cyan-500 hover:text-gray px-3 py-2 rounded-md items-center"
>
<Image
width={40}
height={40}
className="w-10 h-10 rounded-full"
src="https://avatars.githubusercontent.com/u/24878421?s=48&v=4"
alt="Rounded avatar"
/>
<div className="flex items-center">
<span className="px-4 text-sm font-medium inline-flex items-center">
{getEllipsesText(user?.get('ethAddress'))}
</span>
<LogoutIcon className="w-6 h-6 text-white" />
</div>
</>
</button>
)}
</div>
</div>
<div className="-mr-2 flex md:hidden">
{/* Mobile menu button */}
<Disclosure.Button className="bg-gray-800 inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white">
<Disclosure.Button className="bg-cyan-300 inline-flex items-center justify-center p-2 rounded-md text-white hover:text-white hover:bg-cyan-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-cyan-50 focus:ring-white">
<span className="sr-only">Open main menu</span>
{open ? (
<XIcon className="block h-6 w-6" aria-hidden="true" />
Expand All @@ -109,25 +106,18 @@ const Nav = () => {
key={item.name}
as="a"
href={item.href}
className="text-white hover:bg-gray-700 hover:text-gray block px-3 py-2 rounded-md text-base font-medium"
className="text-white hover:bg-blue-600 hover:text-gray block px-3 py-2 rounded-md text-base font-medium"
>
{item.name}
</Disclosure.Button>
))}
</div>
<div className="pt-4 pb-3 border-t border-gray-700">
<div className="pt-4 pb-3 ">
<div className="flex items-center px-5"></div>
<div className="mt-3 px-2 space-y-1">
{userNavigation.map((item) => (
<Disclosure.Button
key={item.name}
as="a"
href={item.href}
className="block px-3 py-2 rounded-md text-base font-medium text-gray-400 hover:text-white hover:bg-gray-700"
>
{item.name}
</Disclosure.Button>
))}
<Disclosure.Button className="block px-3 py-2 rounded-md text-base font-medium text-white hover:bg-blue-600">
{/* {getEllipsesText(user?.get('ethAddress'))} */} coz burayi
</Disclosure.Button>
</div>
</div>
</Disclosure.Panel>
Expand Down
11 changes: 0 additions & 11 deletions src/components/layouts/Home/HomeLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,3 @@ const Landing = ({ children, data }: Props) => {
);
};
export default Landing;

// TODO: ADD LANGUAGE SELECTOR
{
/* <Link href="/" locale="en">
<a className="pl-2">EN</a>
</Link>
<span> | </span>
<Link href="/" locale="tr">
<a>TR</a>
</Link> */
}
13 changes: 9 additions & 4 deletions src/components/layouts/Home/modules/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from 'next/link';
import { IFooter } from '../../../../../interfaces/landing';
import { APP_NAME } from '../../../../../utils/constants';
import { LanguageSelector } from '../../../../common';

interface Props {
data: IFooter;
Expand All @@ -9,9 +9,14 @@ interface Props {
const Footer = ({ data }: Props) => {
const { rights } = data;
return (
<footer className="flex h-24 w-full bg-white drop-shadow-2xl flex-col items-center justify-center p-7 text-center text-xs font-bold tracking-tight text-gray-800 md:flex-row md:p-0 md:text-sm cursor-default">
<span>{rights}&nbsp; </span>
<span>2022 © {APP_NAME}</span>
<footer className="flex h-24 w-full bg-white drop-shadow-2xl flex-col items-center justify-between md:justify-between p-7 text-center text-xs font-bold tracking-tight text-gray-800 md:flex-row md:px-40 md:text-sm cursor-default">
<div className="flex flex-col md:flex-row md:p-0">
<span>{rights}&nbsp; </span>
<span>2022 © {APP_NAME}</span>
</div>
<div className="flex">
<LanguageSelector />
</div>
</footer>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PaperClipIcon } from '@heroicons/react/outline';

const ProfilePage = () => {
const DashboardPage = () => {
return (
<div className="min-h-full">
<div className="bg-white shadow overflow-hidden sm:rounded-lg">
Expand Down Expand Up @@ -109,4 +109,4 @@ const ProfilePage = () => {
);
};

export default ProfilePage;
export default DashboardPage;
2 changes: 1 addition & 1 deletion src/components/templates/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as HomePage } from './HomePage/HomePage';
export { default as ProfilePage } from './ProfilePage/ProfilePage';
export { default as DashboardPage } from './DashboardPage/DashboardPage';
export { default as OtherPage } from './OtherPage/OtherPage';
1 change: 0 additions & 1 deletion src/hooks/useError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useContext } from 'react';
import { ErrorContext } from '../context/Error/errorContext';

// created custom hook
export const useError = () => useContext(ErrorContext);
4 changes: 2 additions & 2 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { NextPage } from 'next';
import { DashboardLayout } from '../../components/layouts';
import { ProfilePage } from '../../components/templates';
import { DashboardPage } from '../../components/templates';

const Dashboard: NextPage = () => {
return (
<DashboardLayout title="dashboard">
<ProfilePage />
<DashboardPage />
</DashboardLayout>
);
};
Expand Down

1 comment on commit 5e3a7fa

@vercel
Copy link

@vercel vercel bot commented on 5e3a7fa Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-dapp-example – ./

nextjs-dapp-example.vercel.app
next-dapp-example-damla.vercel.app
next-dapp-example-git-main-damla.vercel.app

Please sign in to comment.