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 basic Project frontends

Blaumausd96377019c8d
diff --git a/src/pages/Project/Create/CreateProject.container.jsx b/src/pages/Project/Create/CreateProject.container.jsx
new file mode 100644
index 000000000..1865ad490
--- /dev/null
+++ b/src/pages/Project/Create/CreateProject.container.jsx
@@ -0,0 +1,21 @@
+import React from 'react'
+import { useLocation } from 'react-router-dom'
+
+import CreateProject from './CreateProject'
+
+export default () => {
+ const location = useLocation()
+ const { name, id } = location.state || {}
+
+ const onSubmit = () => {
+ // TODO
+ }
+
+ return (
+ <CreateProject
+ onSubmit={onSubmit}
+ name={name}
+ id={id}
+ />
+ )
+}
\ No newline at end of file
diff --git a/src/pages/Project/Create/CreateProject.jsx b/src/pages/Project/Create/CreateProject.jsx
new file mode 100644
index 000000000..3945731f2
--- /dev/null
+++ b/src/pages/Project/Create/CreateProject.jsx
@@ -0,0 +1,124 @@
+import React, { useState, useEffect } from 'react'
+import PropTypes from 'prop-types'
+import Form from 'react-bootstrap/Form'
+import { Link } from 'react-router-dom'
+
+import { nanoid } from 'utils/random'
+import routes from 'routes'
+
+const CreateProject = ({ onSubmit, name, id }) => {
+ const [form, setForm] = useState({
+ name,
+ id: id || nanoid(),
+ })
+ const [validated, setValidated] = useState(false)
+ const [errors, setErrors] = useState({})
+ const [beenSubmitted, setBeenSubmitted] = useState(false)
+
+ useEffect(() => {
+ validate()
+ }, [form])
+
+ const handleInput = event => {
+ const t = event.target
+ const value = t.type === 'checkbox' ? t.checked : t.value
+
+ setForm(form => ({
+ ...form,
+ [t.name]: value,
+ }))
+ }
+
+ const handleSubmit = e => {
+ e.preventDefault()
+ e.stopPropagation()
+ setBeenSubmitted(true)
+
+ if (validated) {
+ onSubmit(form)
+ }
+ }
+
+ const validate = () => {
+ const allErrors = {}
+
+ if (!form.name) {
+ allErrors.name = 'Please enter a project name.'
+ }
+
+ if (form.name.length > 80) {
+ allErrors.name = 'Project name cannot be longer than 80 characters.'
+ }
+
+ const valid = Object.keys(allErrors).length === 0
+
+ setErrors(allErrors)
+ setValidated(valid)
+ }
+
+ return (
+ <div className="container">
+ <h4 className="mb-3">{name ? `${name} settings` : 'Create a new project'}</h4>
+ <Form validated={validated} onSubmit={handleSubmit} noValidate>
+ <Form.Group className="mb-3 has-validation">
+ <Form.Label htmlFor="name">Project name</Form.Label>
+ <Form.Control
+ type="text"
+ value={form.name}
+ placeholder="My awesome project"
+ id="name"
+ className="form-control"
+ name="name"
+ onChange={handleInput}
+ isValid={!errors.hasOwnProperty('name')}
+ isInvalid={beenSubmitted && errors.hasOwnProperty('name')}
+ required
+ />
+ <Form.Control.Feedback type="invalid">
+ {errors.name}
+ </Form.Control.Feedback>
+ </Form.Group>
+ <Form.Group className="mb-3">
+ <Form.Label htmlFor="id">Project ID</Form.Label>
+ <Form.Control
+ type="id"
+ value={form.id}
+ id="id"
+ className="form-control"
+ name="id"
+ onChange={handleInput}
+ isInvalid={beenSubmitted && errors.hasOwnProperty('id')}
+ disabled
+ required
+ />
+ </Form.Group>
+ <div className="d-flex justify-content-right">
+ <Link
+ to={{
+ pathname: id ? routes.project.replace(':id', id) : routes.dashboard,
+ state: { id, name },
+ }}
+ className="btn btn-outline-secondary">
+ Cancel
+ </Link>
+ <button type="submit" className="btn btn-primary ml-2">
+ Save
+ </button>
+ </div>
+ </Form>
+ </div>
+ )
+}
+
+CreateProject.propTypes = {
+ onSubmit: PropTypes.func.isRequired,
+ name: PropTypes.string,
+ id: PropTypes.string,
+}
+
+CreateProject.defaultProps = {
+ name: '',
+ id: '',
+}
+
+export default CreateProject
\ No newline at end of file
diff --git a/src/pages/Project/Create/index.jsx b/src/pages/Project/Create/index.jsx
new file mode 100644
index 000000000..d90d6bc11
--- /dev/null
+++ b/src/pages/Project/Create/index.jsx
@@ -0,0 +1 @@
+export { default } from './CreateProject.container'
\ No newline at end of file
diff --git a/src/pages/Project/View/ViewProject.container.jsx b/src/pages/Project/View/ViewProject.container.jsx
new file mode 100644
index 000000000..e89c2ce75
--- /dev/null
+++ b/src/pages/Project/View/ViewProject.container.jsx
@@ -0,0 +1,40 @@
+import React, { useState } from 'react'
+import { useLocation } from 'react-router-dom'
+import Spinner from 'react-bootstrap/Spinner'
+
+import ViewProject from './ViewProject'
+
+export default () => {
+ const location = useLocation()
+ const { name, id } = location.state || {}
+ const [project, setProject] = useState({})
+
+
+ const onSubmit = () => {
+ // TODO
+ }
+
+ const getProject = () => {
+ // TODO
+ }
+
+ if (id && name) {
+ return (
+ <ViewProject name={name} id={id} />
+ )
+ }
+
+ if (Object.keys(project).length > 0) {
+ return (
+ <ViewProject {...project} />
+ )
+ }
+
+ return (
+ <div className="container d-flex justify-content-center">
+ <Spinner animation="border" role="status" variant="primary" className="spinner-lg">
+ <span className="sr-only">Loading...</span>
+ </Spinner>
+ </div>
+ )
+}
\ No newline at end of file
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
new file mode 100644
index 000000000..55739d816
--- /dev/null
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -0,0 +1,31 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+import { Link } from 'react-router-dom'
+
+import routes from 'routes'
+
+const ViewProject = ({ id, name }) => {
+
+ return (
+ <div className="container">
+ <div className="d-flex justify-content-between">
+ <h2>{name}</h2>
+ <Link
+ to={{
+ pathname: routes.new_project,
+ state: { name, id },
+ }}
+ className="btn btn-outline-primary h-100">
+ Settings
+ </Link>
+ </div>
+ </div>
+ )
+}
+
+ViewProject.propTypes = {
+ id: PropTypes.string.isRequired,
+ name: PropTypes.string.isRequired,
+}
+
+export default ViewProject
\ No newline at end of file
diff --git a/src/pages/Project/View/index.jsx b/src/pages/Project/View/index.jsx
new file mode 100644
index 000000000..72c3942fc
--- /dev/null
+++ b/src/pages/Project/View/index.jsx
@@ -0,0 +1 @@
+export { default } from './ViewProject.container'
\ No newline at end of file