Skip to content

Commit

Permalink
move to new page
Browse files Browse the repository at this point in the history
  • Loading branch information
viloz1 committed Feb 25, 2024
1 parent be18432 commit 39d4f71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 51 deletions.
14 changes: 10 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import { useEffect } from 'react'
function App(): JSX.Element {
const dispatch = useDispatch()
useEffect(() => {
getUser().then(result => {
if (result instanceof Error) {
getUser()
.then(result => {
if (result instanceof Error) {
dispatch(unsetIsAuth())
localStorage.removeItem('jwttoken')
localStorage.removeItem('user')
}
})
.catch(() => {
dispatch(unsetIsAuth())
localStorage.removeItem('jwttoken')
localStorage.removeItem('user')
}
})
})
})

return (
Expand Down
50 changes: 3 additions & 47 deletions src/pages/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ import Tabs from 'react-bootstrap/Tabs'
import Tab from 'react-bootstrap/Tab'
import { getPaginatedPurchases, ReceivedPurchase } from '../api/purchases'
import { useEffect, useState } from 'react'
import { Dropdown, DropdownOption } from '../components/Dropdown'
import { DropdownOption } from '../components/Dropdown'
import Select from 'react-select'
import { AdminModal } from './AdminModal'
import { addUser } from '../api/users'
import { InputField } from '../components/InputField'
import { useForm } from 'react-hook-form'

interface AddUser {
email: string
role: number
}
import { Users } from './Users'

export const Admin = (): JSX.Element => {
const items = []
Expand All @@ -23,19 +16,6 @@ export const Admin = (): JSX.Element => {
const [purchasesPerPage, setPurchasesPerPage] = useState<number>(10)
const [active, setActive] = useState<number>(1)

const {
register,
control,
setValue,
handleSubmit,

// When the resolver does not cover all fields in OurForm, the resolver will give an error
} = useForm<AddUser>()

const onSubmit = async (formData: AddUser) => {
await addUser(formData.email, formData.role)
}

//AdminModal constants
const initPurchase: ReceivedPurchase = {
id: -1,
Expand Down Expand Up @@ -154,13 +134,6 @@ export const Admin = (): JSX.Element => {
{ value: -1, label: 'All' },
]

const roleOptions: DropdownOption[] = [
{ label: 'Admin', value: 1 },
{ label: 'Trasurer', value: 2 },
{ label: 'Regular', value: 3 },
{ label: 'Auditer', value: 4 },
]

return (
<div>
<Tabs
Expand Down Expand Up @@ -241,24 +214,7 @@ export const Admin = (): JSX.Element => {
</div>
</Tab>
<Tab eventKey="profile" title="Profile">
<InputField
name="email"
type="text"
label="Email"
register={register}
/>
<Dropdown
name="role"
label="Choose a role"
options={roleOptions}
control={control}
register={register}
valueChange={(option: DropdownOption | null) => {
option != null && setValue('role', option.value as number)
}}
></Dropdown>
<button onClick={handleSubmit(onSubmit)}>Add user</button>
Tab content for Profile
<Users></Users>
</Tab>
<Tab eventKey="contact" title="Contact" disabled>
Tab content for Contact
Expand Down

0 comments on commit 39d4f71

Please sign in to comment.