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!

Project settings people to ts

kruzhambusec386ce20ead
diff --git a/src/pages/Project/Settings/Emails/Emails.tsx b/src/pages/Project/Settings/Emails/Emails.tsx
index cbc3152e4..f376d1437 100644
--- a/src/pages/Project/Settings/Emails/Emails.tsx
+++ b/src/pages/Project/Settings/Emails/Emails.tsx
@@ -37,8 +37,8 @@ const ModalMessage = ({
handleInput: (e: React.ChangeEvent<HTMLInputElement>) => void
beenSubmitted: boolean
errors: {
- email: string
- reportFrequency: string
+ email?: string
+ reportFrequency?: string
}
form: {
email: string
@@ -294,12 +294,9 @@ const Emails = ({
})
const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
const [errors, setErrors] = useState<{
- email: string,
- reportFrequency: string,
- }>({
- email: '',
- reportFrequency: '',
- })
+ email?: string,
+ reportFrequency?: string,
+ }>({})
const [validated, setValidated] = useState<boolean>(false)
const [emails, setEmails] = useState<ISubscribers[]>([])
const [loading, setLoading] = useState(true)
@@ -330,12 +327,9 @@ const Emails = ({
const validate = () => {
const allErrors: {
- email: string,
- reportFrequency: string,
- } = {
- email: '',
- reportFrequency: '',
- }
+ email?: string,
+ reportFrequency?: string,
+ } = {}
if (!isValidEmail(form.email)) {
allErrors.email = t('auth.common.badEmailError')
@@ -364,10 +358,7 @@ const Emails = ({
const onSubmit = async () => {
setShowModal(false)
- setErrors({
- email: '',
- reportFrequency: '',
- })
+ setErrors({})
setValidated(false)
try {
@@ -399,10 +390,7 @@ const Emails = ({
setShowModal(false)
// a timeout is needed to prevent the flicker of data fields in the modal when closing
setTimeout(() => setForm({ email: '', reportFrequency: '' }), 300)
- setErrors({
- email: '',
- reportFrequency: '',
- })
+ setErrors({})
}
const onRemove = async (email: string) => {
diff --git a/src/pages/Project/Settings/People/People.container.jsx b/src/pages/Project/Settings/People/People.container.jsx
deleted file mode 100644
index 59ffbdf69..000000000
--- a/src/pages/Project/Settings/People/People.container.jsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import { connect } from 'react-redux'
-import UIActions from 'redux/reducers/ui'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
-
-import People from './People'
-
-const mapStateToProps = (state) => ({
- isPaidTierUsed: state.auth.isPaidTierUsed,
-})
-
-const mapDispatchToProps = (dispatch) => ({
- updateProjectFailed: (message) => {
- dispatch(errorsActions.updateProjectFailed(message))
- },
- setProjectShareData: (projectId, share) => {
- dispatch(UIActions.setProjectsShareData(projectId, share))
- },
- roleUpdatedNotification: (message, type = 'success') => {
- dispatch(alertsActions.roleUpdated(message, type))
- },
- inviteUserNotification: (message, type = 'success') => {
- dispatch(alertsActions.inviteUser(message, type))
- },
- removeUserNotification: (message, type = 'success') => {
- dispatch(alertsActions.removeUser(message, type))
- },
-})
-
-export default connect(mapStateToProps, mapDispatchToProps)(People)
diff --git a/src/pages/Project/Settings/People/People.container.tsx b/src/pages/Project/Settings/People/People.container.tsx
new file mode 100644
index 000000000..f7af17de0
--- /dev/null
+++ b/src/pages/Project/Settings/People/People.container.tsx
@@ -0,0 +1,47 @@
+import { connect } from 'react-redux'
+import UIActions from 'redux/reducers/ui'
+import { errorsActions } from 'redux/reducers/errors'
+import { alertsActions } from 'redux/reducers/alerts'
+import { StateType, AppDispatch } from 'redux/store'
+import { IProject } from 'redux/models/IProject'
+
+import People from './People'
+
+const mapStateToProps = (state: StateType) => ({
+ isPaidTierUsed: state.auth.isPaidTierUsed,
+})
+
+const mapDispatchToProps = (dispatch: AppDispatch) => ({
+ updateProjectFailed: (message: string) => {
+ dispatch(errorsActions.updateProjectFailed({
+ message,
+ }))
+ },
+ setProjectShareData: (data: Partial<IProject>, projectId: string, share = true) => {
+ dispatch(UIActions.setProjectsShareData({
+ data,
+ id: projectId,
+ shared: share,
+ }))
+ },
+ roleUpdatedNotification: (message: string, type = 'success') => {
+ dispatch(alertsActions.roleUpdated({
+ message,
+ type,
+ }))
+ },
+ inviteUserNotification: (message: string, type = 'success') => {
+ dispatch(alertsActions.inviteUser({
+ message,
+ type,
+ }))
+ },
+ removeUserNotification: (message: string, type = 'success') => {
+ dispatch(alertsActions.removeUser({
+ message,
+ type,
+ }))
+ },
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(People)
diff --git a/src/pages/Project/Settings/People/People.jsx b/src/pages/Project/Settings/People/People.tsx
similarity index 88%
rename from src/pages/Project/Settings/People/People.jsx
rename to src/pages/Project/Settings/People/People.tsx
index 85754a43d..427258901 100644
--- a/src/pages/Project/Settings/People/People.jsx
+++ b/src/pages/Project/Settings/People/People.tsx
@@ -21,8 +21,11 @@ import {
roles, roleViewer, roleAdmin, INVITATION_EXPIRES_IN,
} from 'redux/constants'
import useOnClickOutside from 'hooks/useOnClickOutside'
+import { IProject, IShareOwnerProject } from 'redux/models/IProject'
-const NoEvents = ({ t }) => (
+const NoEvents = ({ t }: {
+ t: (key: string) => string
+}): JSX.Element => (
<div className='flex flex-col py-6 sm:px-6 lg:px-8'>
<div className='max-w-7xl w-full mx-auto text-gray-900 dark:text-gray-50'>
<h2 className='text-2xl mb-8 text-center leading-snug'>
@@ -34,19 +37,31 @@ const NoEvents = ({ t }) => (
const UsersList = ({
data, onRemove, t, share, setProjectShareData, pid, updateProjectFailed, language, roleUpdatedNotification,
+}: {
+ data: IShareOwnerProject
+ onRemove: (id: string) => void
+ t: (key: string, options?: {
+ [key: string]: string | number | null
+ }) => string
+ share?: IShareOwnerProject[]
+ setProjectShareData: (item: Partial<IProject>, id: string) => void
+ pid: string
+ updateProjectFailed: (message: string) => void
+ language: string
+ roleUpdatedNotification: (email: string, role?: string) => void
}) => {
- const [open, setOpen] = useState(false)
- const [showDeleteModal, setShowDeleteModal] = useState(false)
- const openRef = useRef()
+ const [open, setOpen] = useState<boolean>(false)
+ const [showDeleteModal, setShowDeleteModal] = useState<boolean>(false)
+ const openRef = useRef<HTMLDivElement>(null)
useOnClickOutside(openRef, () => setOpen(false))
const {
id, created, confirmed, role, user,
} = data
- const changeRole = async (newRole) => {
+ const changeRole = async (newRole: string) => {
try {
const results = await changeShareRole(id, { role: newRole })
- const newShared = _map(share, (itShare) => {
+ const newShared: IShareOwnerProject[] = _map(share, (itShare) => {
if (itShare.id === results.id) {
return { ...results, user: itShare.user }
}
@@ -166,24 +181,50 @@ UsersList.defaultProps = {
data: {},
}
-const People = ({
+interface IPeopleProps {
+ project: IProject,
+ updateProjectFailed: (error: string) => void,
+ setProjectShareData: (data: Partial<IProject>, projectId: string, share?: boolean) => void,
+ roleUpdatedNotification: (email: string, role?: string) => void,
+ inviteUserNotification: (email: string, type?: string) => void,
+ removeUserNotification: (email: string) => void,
+ isPaidTierUsed: boolean,
+}
+
+const People: React.FunctionComponent<IPeopleProps> = ({
project, updateProjectFailed, setProjectShareData, roleUpdatedNotification, inviteUserNotification,
removeUserNotification, isPaidTierUsed,
-}) => {
- const [showModal, setShowModal] = useState(false)
- const [isPaidFeatureOpened, setIsPaidFeatureOpened] = useState(false)
- const { t, i18n: { language } } = useTranslation('common')
- const [form, setForm] = useState({
+}: IPeopleProps): JSX.Element => {
+ const [showModal, setShowModal] = useState<boolean>(false)
+ const [isPaidFeatureOpened, setIsPaidFeatureOpened] = useState<boolean>(false)
+ const { t, i18n: { language } }: {
+ t: (key: string, options?: {
+ [key: string]: string | number | null
+ }) => string,
+ i18n: {
+ language: string
+ }
+ } = useTranslation('common')
+ const [form, setForm] = useState<{
+ email: string,
+ role: string,
+ }>({
email: '',
role: '',
})
- const [beenSubmitted, setBeenSubmitted] = useState(false)
- const [errors, setErrors] = useState({})
- const [validated, setValidated] = useState(false)
+ const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
+ const [errors, setErrors] = useState<{
+ email?: string,
+ role?: string,
+ }>({})
+ const [validated, setValidated] = useState<boolean>(false)
const { id, name, share } = project
const validate = () => {
- const allErrors = {}
+ const allErrors: {
+ email?: string,
+ role?: string,
+ } = {}
if (!isValidEmail(form.email)) {
allErrors.email = t('auth.common.badEmailError')
@@ -205,7 +246,7 @@ const People = ({
}
}, [form]) // eslint-disable-line
- const handleInput = ({ target }) => {
+ const handleInput = ({ target }: React.ChangeEvent<HTMLInputElement>) => {
const value = target.type === 'checkbox' ? target.checked : target.value
setForm(oldForm => ({
@@ -232,7 +273,7 @@ const People = ({
setTimeout(() => setForm({ email: '', role: '' }), 300)
}
- const handleSubmit = e => {
+ const handleSubmit = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault()
e.stopPropagation()
@@ -256,7 +297,7 @@ const People = ({
setErrors({})
}
- const onRemove = async (userId) => {
+ const onRemove = async (userId: string) => {
try {
await deleteShareProjectUsers(id, userId)
const newShared = _map(_filter(share, s => s.id !== userId), s => s)
@@ -286,8 +327,10 @@ const People = ({
type='button'
onClick={() => setShowModal(true)}
>
- <UserPlusIcon className='w-5 h-5 mr-1' />
- {t('project.settings.invite')}
+ <>
+ <UserPlusIcon className='w-5 h-5 mr-1' />
+ {t('project.settings.invite')}
+ </>
</Button>
</div>
<div>
@@ -437,6 +480,7 @@ const People = ({
}
People.propTypes = {
+ // @ts-ignore
// eslint-disable-next-line react/forbid-prop-types
project: PropTypes.object.isRequired,
updateProjectFailed: PropTypes.func.isRequired,
diff --git a/src/pages/Project/Settings/People/index.jsx b/src/pages/Project/Settings/People/index.tsx
similarity index 100%
rename from src/pages/Project/Settings/People/index.jsx
rename to src/pages/Project/Settings/People/index.tsx