Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

added project to dashboard and user settings, added modal, some update

kruzhambus1dbd1e0e8df2
diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsx
index a06a629b8..ea7430b01 100644
--- a/src/pages/Dashboard/Dashboard.jsx
+++ b/src/pages/Dashboard/Dashboard.jsx
@@ -24,19 +24,27 @@ import { isSelfhosted } from 'redux/constants'
import EventsRunningOutBanner from 'components/EventsRunningOutBanner'
const ProjectCart = ({
- name, url, created, active, overall, t, language, live, isPublic,
+ name, created, active, overall, t, language, live, isPublic, confirmed,
}) => {
const statsDidGrowUp = overall?.percChange >= 0
+ const [showInviteModal, setShowInviteModal] = useState(false)
return (
<li>
- <Link to={url} className='block hover:bg-gray-50 dark:bg-gray-700 dark:hover:bg-gray-800 dark:border-gray-700'>
+ <div onClick={() => { return confirmed === false ? setShowInviteModal(true) : () => {} }} className='block cursor-pointer hover:bg-gray-50 dark:bg-gray-700 dark:hover:bg-gray-800 dark:border-gray-700'>
<div className='px-4 py-4 sm:px-6'>
<div className='flex items-center justify-between'>
<p className='text-lg font-medium text-indigo-600 dark:text-gray-50 truncate'>
{name}
</p>
<div className='ml-2 flex-shrink-0 flex'>
+ {
+ confirmed ? (
+ <ActivePin className='mr-2' label='Shared' />
+ ) : (
+ <InactivePin className='mr-2' label='Panding' />
+ )
+ }
{active ? (
<ActivePin label={t('dashboard.active')} />
) : (
@@ -107,7 +115,21 @@ const ProjectCart = ({
</div>
</div>
</div>
- </Link>
+ </div>
+ {
+ !confirmed && (
+ <Modal
+ onClose={() => { setShowInviteModal(false) }}
+ onSubmit={() => { setShowInviteModal(false) }}
+ submitText='Accept & Continue'
+ type='confirmed'
+ closeText='Reject'
+ title={`Invitanion for ${name}`}
+ message='You have been invited to join this project. Do you want to accept?'
+ isOpened={showInviteModal}
+ />
+ )
+ }
</li>
)
}
@@ -178,20 +200,38 @@ const Dashboard = ({
<div className='bg-white shadow overflow-hidden sm:rounded-md mt-10'>
<ul className='divide-y divide-gray-200 dark:divide-gray-500'>
{_map(_filter(projects, ({ uiHidden }) => !uiHidden), ({
- name, id, created, active, overall, live, public: isPublic,
+ name, id, created, active, overall, live, public: isPublic, confirmed,
}) => (
- <ProjectCart
- key={id}
- t={t}
- language={language}
- name={name}
- created={created}
- active={active}
- isPublic={isPublic}
- overall={overall}
- live={_isNumber(live) ? live : 'N/A'}
- url={_replace(routes.project, ':id', id)}
- />
+ <div key={confirmed ? `${id}-confirmed` : id}>
+ {
+ confirmed === false ? (
+ <ProjectCart
+ t={t}
+ language={language}
+ name={name}
+ created={created}
+ active={active}
+ isPublic={isPublic}
+ overall={overall}
+ confirmed={confirmed}
+ live={_isNumber(live) ? live : 'N/A'}
+ />
+ ) : (
+ <Link to={_replace(routes.project, ':id', id)}>
+ <ProjectCart
+ t={t}
+ language={language}
+ name={name}
+ created={created}
+ active={active}
+ isPublic={isPublic}
+ overall={overall}
+ live={_isNumber(live) ? live : 'N/A'}
+ />
+ </Link>
+ )
+ }
+ </div>
))}
</ul>
</div>
diff --git a/src/pages/Project/Settings/People/People.jsx b/src/pages/Project/Settings/People/People.jsx
index e8ef14c36..b42b28539 100644
--- a/src/pages/Project/Settings/People/People.jsx
+++ b/src/pages/Project/Settings/People/People.jsx
@@ -1,7 +1,8 @@
import React, { useState, useEffect } from 'react'
import Button from 'ui/Button'
import { ChevronDownIcon, CheckIcon } from '@heroicons/react/solid'
-import { ActivePin, InactivePin } from 'ui/Pin'
+import { TrashIcon } from '@heroicons/react/outline'
+import { ActivePin } from 'ui/Pin'
import Modal from 'ui/Modal'
import { useTranslation } from 'react-i18next'
import Input from 'ui/Input'
@@ -10,10 +11,10 @@ import _keys from 'lodash/keys'
import _isEmpty from 'lodash/isEmpty'
import cx from 'clsx'
import _map from 'lodash/map'
-import _filter from 'lodash/filter'
-
import { deleteShareProject, shareProject } from 'api'
+import PropTypes from 'prop-types'
+
const roles = [
{
name: 'Admin',
@@ -39,6 +40,7 @@ const NoEvents = () => (
const UsersList = ({ data, onRemove }) => {
const [open, setOpen] = useState(false)
+ const [showDeleteModal, setShowDeleteModal] = useState(false)
return (
<li className='py-4'>
@@ -46,7 +48,7 @@ const UsersList = ({ data, onRemove }) => {
<p className='text-gray-700 dark:text-gray-200'>
{data.id}
</p>
- <div className='relative'>
+ <div className={cx('relative', { 'flex items-center': !data.confirmed })}>
{
!data.confirmed ? (
<>
@@ -54,12 +56,14 @@ const UsersList = ({ data, onRemove }) => {
label='Pannding'
className='inline-flex items-center shadow-sm px-2.5 py-0.5 mr-3'
/>
- <span onClick={() => onRemove(data.id)}>
- <InactivePin
- label='Remove'
- className='cursor-pointer inline-flex items-center shadow-sm px-2.5 py-0.5 hover:text-red-400 hover:dark:text-red-400'
- />
- </span>
+ <Button
+ type='button'
+ className='bg-white text-indigo-600 border border-transparent rounded-md text-base font-medium hover:bg-indigo-50 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600'
+ small
+ onClick={() => { setShowDeleteModal(true) }}
+ >
+ <TrashIcon className='h-4 w-4' />
+ </Button>
</>
) : (
<>
@@ -93,7 +97,7 @@ const UsersList = ({ data, onRemove }) => {
)}
</li>
))}
- <li onClick={() => { setOpen(false); onRemove(data.gmail) }} className='p-4 hover:bg-gray-900 group cursor-pointer flex justify-between items-center'>
+ <li onClick={() => { setOpen(false); setShowDeleteModal(true) }} className='p-4 hover:bg-gray-900 group cursor-pointer flex justify-between items-center'>
<div>
<p className='font-bold text-red-600 group-hover:text-red-600'>
Remove member
@@ -102,17 +106,41 @@ const UsersList = ({ data, onRemove }) => {
</li>
</ul>
)}
-
</>
)
}
</div>
</div>
+ <Modal
+ onClose={() => {
+ setShowDeleteModal(false)
+ }}
+ onSubmit={() => {
+ setShowDeleteModal(false)
+ onRemove(data.id)
+ }}
+ submitText='Yes'
+ type='confirmed'
+ closeText='No'
+ title={`Delete user: ${data.id}?`}
+ message='Are you sure you want to delete this user?'
+ isOpened={showDeleteModal}
+ />
</li>
)
}
-const People = ({ project, updateProjectFailed }) => {
+UsersList.propTypes = {
+ // eslint-disable-next-line react/forbid-prop-types
+ data: PropTypes.object.isRequired,
+ onRemove: PropTypes.func,
+}
+
+UsersList.defaultProps = {
+ onRemove: () => {},
+}
+
+const People = ({ project, updateProjectFailed, loadProjects }) => {
const [showModal, setShowModal] = useState(false)
const { t } = useTranslation('common')
const [form, setForm] = useState({
@@ -124,8 +152,6 @@ const People = ({ project, updateProjectFailed }) => {
const [validated, setValidated] = useState(false)
const { id, name, share } = project
- const [users, setUsers] = useState(share)
-
const validate = () => {
const allErrors = {}
@@ -164,8 +190,8 @@ const People = ({ project, updateProjectFailed }) => {
setErrors({})
setValidated(false)
shareProject(id, { email: form.email, role: form.role })
- .then((data) => {
- setUsers(data.share)
+ .then(() => {
+ loadProjects()
})
.catch((e) => {
updateProjectFailed(e)
@@ -193,7 +219,7 @@ const People = ({ project, updateProjectFailed }) => {
deleteShareProject(id, userId)
.then((data) => {
console.log(data)
- setUsers(oldUsers => _filter(oldUsers, user => user.id !== userId))
+ loadProjects()
})
.catch((e) => {
updateProjectFailed(e)
@@ -223,11 +249,11 @@ const People = ({ project, updateProjectFailed }) => {
</div>
<div>
{
- !users ? (
+ _isEmpty(share) ? (
<NoEvents />
) : (
<ul className='divide-y divide-gray-200 dark:divide-gray-700'>
- {_map(users, user => (<UsersList data={user} key={user.id} onRemove={onRemove} />))}
+ {_map(share, user => (<UsersList data={user} key={user.id} onRemove={onRemove} />))}
</ul>
)
}
@@ -318,4 +344,16 @@ const People = ({ project, updateProjectFailed }) => {
)
}
+People.propTypes = {
+ // eslint-disable-next-line react/forbid-prop-types
+ project: PropTypes.object.isRequired,
+ updateProjectFailed: PropTypes.func,
+ loadProjects: PropTypes.func,
+}
+
+People.defaultProps = {
+ updateProjectFailed: () => {},
+ loadProjects: () => {},
+}
+
export default People
diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsx
index 7b86fbffb..b2fcd8be6 100644
--- a/src/pages/UserSettings/UserSettings.jsx
+++ b/src/pages/UserSettings/UserSettings.jsx
@@ -21,6 +21,57 @@ import {
isValidEmail, isValidPassword, MIN_PASSWORD_CHARS,
} from 'utils/validator'
+const ProjectList = ({ item, t }) => {
+ const [showDeleteModal, setShowDeleteModal] = useState(false)
+
+ return (
+ <tr className='dark:bg-gray-700'>
+ <td className='whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 dark:text-white sm:pl-6'>
+ {item.id}
+ </td>
+ <td className='whitespace-nowrap px-3 py-4 text-sm text-gray-900 dark:text-white'>
+ {item.role}
+ </td>
+ <td className='relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6'>
+ {item.confirmed === false ? (
+ <>
+ <Button className='mr-2' onClick={() => {}} primary small>
+ Reject
+ </Button>
+ <Button onClick={() => {}} primary small>
+ Accept
+ </Button>
+ </>
+ ) : (
+ <>
+ <button
+ type='button'
+ className='text-indigo-600 hover:text-indigo-900'
+ onClick={() => setShowDeleteModal(true)}
+ >
+ Delete
+ </button>
+ <Modal
+ onClose={() => {
+ setShowDeleteModal(false)
+ }}
+ onSubmit={() => {
+ setShowDeleteModal(false)
+ }}
+ submitText={t('common.yes')}
+ type='confirmed'
+ closeText={t('common.no')}
+ title={`Delete ${item.id}?`}
+ message='Are you sure you want to delete this project?'
+ isOpened={showDeleteModal}
+ />
+ </>
+ )}
+ </td>
+ </tr>
+ )
+}
+
const UserSettings = ({
onDelete, onExport, onSubmit, onEmailConfirm, onDeleteProjectCache, t,
}) => {
@@ -208,11 +259,11 @@ const UserSettings = ({
Projects
</h3>
<div>
- <div className='mt-8 flex flex-col'>
+ <div className='mt-3 flex flex-col'>
<div className='-my-2 -mx-4 overflow-x-auto sm:-mx-6 lg:-mx-8'>
<div className='inline-block min-w-full py-2 align-middle md:px-6 lg:px-8'>
<div className='overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg'>
- <table className='min-w-full divide-y divide-gray-600'>
+ <table className='min-w-full divide-y divide-gray-300 dark:divide-gray-600'>
<thead>
<tr className='dark:bg-gray-700'>
<th scope='col' className='py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6 dark:text-white'>
@@ -226,29 +277,12 @@ const UserSettings = ({
</th>
</tr>
</thead>
- <tbody className='divide-y divide-gray-600'>
- <tr key='1' className='dark:bg-gray-700'>
- <td className='whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 dark:text-white sm:pl-6'>
- le chiffe cheat
- </td>
- <td className='whitespace-nowrap px-3 py-4 text-sm text-gray-500 dark:text-white'>Admin</td>
- <td className='relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6'>
- <button type='button' className='text-indigo-600 hover:text-indigo-900'>
- Delete
- </button>
- </td>
- </tr>
- <tr key='2' className='dark:bg-gray-700'>
- <td className='whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 dark:text-white sm:pl-6'>
- some project
- </td>
- <td className='whitespace-nowrap px-3 py-4 text-sm text-gray-500 dark:text-white'>Viewr</td>
- <td className='relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6'>
- <button type='button' className='text-indigo-600 hover:text-indigo-900'>
- Delete
- </button>
- </td>
- </tr>
+ <tbody className='divide-y divide-gray-300 dark:divide-gray-600'>
+ {
+ _map(user.sharedProjects, (item) => (
+ <ProjectList key={item.id} item={item} t={t} />
+ ))
+ }
</tbody>
</table>
</div>
diff --git a/src/redux/sagas/ui/load_projects.js b/src/redux/sagas/ui/load_projects.js
index 136270dca..ba67d81b8 100644
--- a/src/redux/sagas/ui/load_projects.js
+++ b/src/redux/sagas/ui/load_projects.js
@@ -13,7 +13,13 @@ const debug = Debug('swetrix:rx:s:load-projects')
export default function* loadProjects() {
try {
// eslint-disable-next-line prefer-const
- let { results, totalMonthlyEvents } = yield call(getProjects)
+ let { results, totalMonthlyEvents, shared } = yield call(getProjects)
+ const projectWithShared = [..._map(shared, (item) => {
+ return {
+ confirmed: item.confirmed,
+ ...item.project,
+ }
+ }), ...results]
const pids = _map(results, result => result.id)
let overall
@@ -23,10 +29,11 @@ export default function* loadProjects() {
debug('failed to overall stats: %s', e)
}
- results = _map(results, res => ({
+ results = _map(projectWithShared, res => ({
...res,
overall: overall?.[res.id],
}))
+
yield put(UIActions.setProjects(results))
yield put(UIActions.setTotalMonthlyEvents(totalMonthlyEvents))
diff --git a/src/ui/Modal.jsx b/src/ui/Modal.jsx
index d97b419c7..925c0a77e 100644
--- a/src/ui/Modal.jsx
+++ b/src/ui/Modal.jsx
@@ -2,7 +2,9 @@ import React, { Fragment, memo } from 'react'
import PropTypes from 'prop-types'
import cx from 'clsx'
import { Dialog, Transition } from '@headlessui/react'
-import { CheckIcon, ExclamationIcon, InformationCircleIcon } from '@heroicons/react/outline'
+import {
+ CheckIcon, ExclamationIcon, InformationCircleIcon, UserGroupIcon,
+} from '@heroicons/react/outline'
const Modal = ({
className, type, title, message, isOpened, onClose, onSubmit, closeText, submitText, submitType, size,
@@ -44,25 +46,30 @@ const Modal = ({
>
<div className='sm:flex sm:items-start'>
{type === 'success' && (
- <div className='mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10'>
+ <div className='mr-3 mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:h-10 sm:w-10'>
<CheckIcon className='h-6 w-6 text-green-600' aria-hidden='true' />
</div>
)}
{type === 'error' && (
- <div className='mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10'>
+ <div className='mr-3 mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:h-10 sm:w-10'>
<ExclamationIcon className='h-6 w-6 text-red-600' aria-hidden='true' />
</div>
)}
{type === 'info' && (
- <div className='mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-blue-100 sm:mx-0 sm:h-10 sm:w-10'>
+ <div className='mr-3 mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-blue-100 sm:h-10 sm:w-10'>
<InformationCircleIcon className='h-6 w-6 text-blue-600' aria-hidden='true' />
</div>
)}
{type === 'warning' && (
- <div className='mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-orange-100 sm:mx-0 sm:h-10 sm:w-10'>
+ <div className='mr-3 mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-orange-100 sm:h-10 sm:w-10'>
<ExclamationIcon className='h-6 w-6 text-amber-600' aria-hidden='true' />
</div>
)}
+ {type === 'confirmed' && (
+ <div className='mr-3 mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:h-10 sm:w-10'>
+ <UserGroupIcon className='h-6 w-6 text-green-600' aria-hidden='true' />
+ </div>
+ )}
<div className='mt-3 text-center sm:mt-0 sm:text-left w-full'>
{title && (
<Dialog.Title as='h3' className='text-lg leading-6 font-medium text-gray-900 dark:text-gray-50'>
@@ -106,7 +113,7 @@ const Modal = ({
}
Modal.propTypes = {
- type: PropTypes.oneOf(['error', 'success', 'info', 'warning']),
+ type: PropTypes.oneOf(['error', 'success', 'info', 'warning', 'confirmed']),
title: PropTypes.string,
onClose: PropTypes.func.isRequired,
message: PropTypes.oneOfType([