Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marcos/edit member infov3 #69

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2e0e2d3
nothing changed
christianjc Dec 4, 2022
ac7be92
Merge branch 'main' of github.com:calblueprint/berkeley-student-coope…
christianjc Feb 8, 2023
4b43807
husky installed
christianjc Feb 8, 2023
7859d93
pulled changes from github
christianjc Feb 27, 2023
545e4a4
fixed packet.json file
christianjc Feb 27, 2023
ffe7d0e
updated package.json
christianjc Feb 27, 2023
e5b8073
setting up Redux and RTK Query. I have set up the redux store and I a…
christianjc Feb 28, 2023
6a1ae94
fixed consoled error, and still wokring on redux and RTK Query
christianjc Mar 1, 2023
a324a8c
set up main apiSlice and shiftsApiSlice
christianjc Mar 1, 2023
00b3949
mereged changes from christian's branch to dev/redux with the basic r…
christianjc Mar 1, 2023
2da2fb2
Set basic redux set up as well as the main apiSlide and the shift co…
christianjc Mar 1, 2023
6eea657
Merge branch 'christian/redux' into dev/redux
christianjc Mar 1, 2023
b7a3bcd
fixed the filtering for unassigned users
christianjc Mar 1, 2023
9c35cf9
woring on unassign and created usersApiSlices
christianjc Mar 1, 2023
91de215
added redux api for users
christianjc Mar 2, 2023
7bd6216
Merge branch 'christian/redux' into dev/redux
christianjc Mar 2, 2023
b0945fe
added some notes
gregoriiaaa Mar 2, 2023
dfeb1a1
merged dev/redux into dev/main and resolved conflicts
gregoriiaaa Mar 2, 2023
19c0aa5
fixing apiSlice errors
gregoriiaaa Mar 4, 2023
50bf0eb
hold up
gregoriiaaa Mar 4, 2023
b464713
npm i
gregoriiaaa Mar 6, 2023
d9c52d8
merged main onto branch
gregoriiaaa Mar 6, 2023
2f31cb4
pull from github
christianjc Mar 6, 2023
4bedefa
setting up testing component for redux
christianjc Mar 6, 2023
eb0e6ae
getshift is working
christianjc Mar 6, 2023
6689e09
updated testing readux file
christianjc Mar 6, 2023
f9e75e9
Merge branch 'main' of github.com:calblueprint/berkeley-student-coope…
gregoriiaaa Mar 6, 2023
8a24672
Merge branch 'greg/fixing-api-bugs' into dev/redux-update
christianjc Mar 6, 2023
62df4ae
Merge branch 'dev/redux-update' into dev/redux
christianjc Mar 6, 2023
d940885
added packages and added CustomFormikFields file
christianjc Mar 6, 2023
6d34f42
updating schema
gregoriiaaa Mar 6, 2023
51fba24
added skeleton of the ScheduledShift type
gregoriiaaa Mar 6, 2023
611d92c
fixing shift form
christianjc Mar 6, 2023
930b3da
updating ShiftForm file
christianjc Mar 6, 2023
b3199d3
Merge branch 'dev/updating-types' into dev/forms
christianjc Mar 6, 2023
11896e2
added functionality to add new shift, not fully tested
christianjc Mar 6, 2023
a8221d1
Merge branch 'dev/forms' into dev/redux-update
christianjc Mar 6, 2023
eabd1db
getShifts and addNewShift works
christianjc Mar 6, 2023
9aabee7
implemented providesTags which allows componets to update when data c…
christianjc Mar 6, 2023
93dd843
made some small changes
christianjc Mar 7, 2023
6894521
Merge branch 'dev/redux-update' into dev/forms
christianjc Mar 7, 2023
d0011f4
editin shifts update
christianjc Mar 7, 2023
f9ab769
Merge branch 'dev/forms' into dev/redux-update
christianjc Mar 7, 2023
1a80855
Fixed the selectShiftById
christianjc Mar 8, 2023
682fc07
will change formik fields
christianjc Mar 8, 2023
635e87b
Merge branch 'dev/redux-apiSlice' into dev/forms
christianjc Mar 8, 2023
44310b5
fixed ShiftForm and formik filds
christianjc Mar 9, 2023
6120855
fixed Post bug
christianjc Mar 9, 2023
45a93d3
Merge branch 'dev/redux-apiSlice' into dev/forms
christianjc Mar 9, 2023
6866ca0
updated shiftForm
christianjc Mar 9, 2023
d3aeead
Merge branch 'dev/forms' of github.com:calblueprint/berkeley-student-…
gregoriiaaa Mar 9, 2023
a7422a7
updated userApi
christianjc Mar 9, 2023
c8bd4a1
fixed user Api
christianjc Mar 9, 2023
841d21a
updated the forms for users
christianjc Mar 9, 2023
b51f1ad
added userForm and editUserCard
christianjc Mar 9, 2023
3ef7b29
added house api slice with fetch, update, and add queries
danashimessele Mar 9, 2023
aa58c36
Merge branch 'dev/reduxHosueApi' of github.com:calblueprint/berkeley-…
gregoriiaaa Mar 11, 2023
43f5588
fixed getHousesQuery
danashimessele Mar 11, 2023
e31a249
greg stuff
gregoriiaaa Mar 11, 2023
4dffcc7
Merge branch 'Danashi/HouseUpdates' of github.com:calblueprint/berkel…
gregoriiaaa Mar 11, 2023
c1b65bf
[feat] Edit User Card in Planner created to edit only the user's name…
Mar 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated userApi
  • Loading branch information
christianjc committed Mar 9, 2023
commit a7422a76a360d4ac81cce731c68a1634bcd0b1cc
218 changes: 218 additions & 0 deletions src/components/ManagerComponents/userCard/UserForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import { Formik, Form, FormikHelpers, FormikValues } from 'formik'
import { Stack, Button } from '@mui/material'

import dayjs from 'dayjs'
import * as Yup from 'yup'
import { TextInput, SelectInput } from '../../shared/forms/CustomFormikFields'
import {
selectUserById,
useAddNewUserMutation,
useUpdateUserMutation,
} from '../../../store/apiSlices/userApiSlice'
// import { getCategories } from '../../../firebase/queries/house'
import { useSelector } from 'react-redux'
import React from 'react'
import { RootState } from '../../../store/store'
import { EntityId } from '@reduxjs/toolkit'
import { User } from '../../../types/schema'
// import { useUserContext } from '../../../context/UserContext'

//** Yup allows us to define a schema, transform a value to match, and/or assert the shape of an existing value. */
//** Here, we are defining what kind of inputs we are expecting and attaching error msgs for when the input is not what we want. */
const UserSchema = Yup.object({
firstName: Yup.string(),
lastName: Yup.string(),
displayName: Yup.string().required('Display Name is required'),
email: Yup.string(),
role: Yup.string(),
houseID: Yup.string(),
hoursAssigned: Yup.number(),
pinNumber: Yup.number(),
assignedScheduledShifts: Yup.array().of(Yup.string()),
weekMissedHours: Yup.number(),
weekPenaltyHours: Yup.number(),
runningTotalMissedHours: Yup.number(),
runningTotalPenatlyHours: Yup.number(),
})

const daysList = [
'',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
]

const userCategories = [
'cook dinner',
'clean bathroom',
'wash dishes',
'clean basement',
]

const emptyUser = {
// Role of the user
role: '',
// Last Name
lastName: '',
// First Name
firstName: '',
// full name that gets displayed
displayName: '',
// User email
email: '',
// The houseID of the house that the user resides in
houseID: '',
// Hours the user has been assigned
hoursAssigned: 0,
// Hours the user must be assigned, always set to 5

// Pin Number for verifying other people's tasks
pinNumber: 0,
// Total fines assessed to this user

// Map of availabilities (day: time windows when they're free)
// availabilities: { string: number[] }
// Map of preferences (taskID: (0/1/2 (higher number = greater preference)))
// preferences: { string: number }

//** new attributes below */

// The scheduled shifts that the user has been assigned
assignedScheduledShifts: [],
// Missed workshift hours this user has missed this current week
weekMissedHours: 0,
// Hours that manager has added to this user as a penatly for missing a shift this current week
weekPenaltyHours: '',
// The running total of missed workshift hours for the whole semester
runningTotalMissedHours: '',
// The running total of penalty hours for the whole semester
runningTotalPenatlyHours: '',
}

const UserForm = ({
setOpen,
userId,
isNewUser,
}: {
setOpen: (value: React.SetStateAction<boolean>) => void
userId?: string
isNewUser: boolean
}) => {
// const { authUser, house } = useUserContext()
// const [currentUser, setCurrentUser] = React.useState(User)

// const userCategories = getCategories(house.houseID) //TODO: use redux api slice once implemented

//* Get API helpers to create or update a user
const [
addNewUser,
{
// isLoading: isLoadingNewUser,
// isSuccess: isSuccessNewUser,
// isError: isErrorNewUser,
// error: errorNewUser,
},
] = useAddNewUserMutation()
const [
updateUser,
{
// isLoading: isLoadingUpdateUser,
// isSuccess: isSuccessUpdateUser,
// isError: isErrorUpdateUser,
// error: errorUpdateUser,
},
] = useUpdateUserMutation()

const user: User = useSelector(
(state: RootState) =>
selectUserById('EUC')(state, userId as EntityId) as User
)

const onSubmit = async (
values: FormikValues,
formikBag: FormikHelpers<FormikValues>
) => {
// console.log('Submiting UserForm: ', values)
const { name } = values

// console.log(dayjs('1900', 'HHmm').format('HHmm'))
// const num = 1900
// console.log(dayjs(num.toString(), 'HHmm'))

// const dayString = possibleDays.join('')
let result

const data = { data: {}, houseId: '', userId: '' }
data.data = {
name,
}
data.houseId = 'EUC'
data.userId = userId ? userId : ''
// console.log('data: ', data)
if (isNewUser || !userId) {
result = await addNewUser(data)
} else {
result = await updateUser(data)
}
if (result) {
console.log('success with user: ', result)
}

formikBag.resetForm()
setOpen(false)
}

// React.useEffect(() => {
// console.log('This is the selected user', user)
// }, [user])

return (
<>
<Formik
validationSchema={UserSchema}
initialValues={{
firstName: user ? user.firstName : emptyUser.firstName,
lastName: user ? user.lastName : emptyUser.lastName,
displayName: user ? user.displayName : emptyUser.displayName,
email: user ? user.email : emptyUser.email,
role: user ? user.role : emptyUser.role,
}}
onSubmit={onSubmit}
>
{({ isSubmitting, values, setFieldValue }) => (
<Form>
<TextInput name="firstName" label="First Name" />
<TextInput name="lastName" label="Last Name" />
<TextInput name="displayName" label="Display Name" />

<Stack direction="row" alignItems="center" spacing={2}>
<Button
type="submit"
fullWidth
variant="contained"
color="primary"
disabled={isSubmitting}
>
{isNewUser || !userId ? 'Submit' : 'Update'}
</Button>
<Button
fullWidth
variant="outlined"
color="primary"
onClick={() => setOpen(false)}
>
Cancel
</Button>
</Stack>
</Form>
)}
</Formik>
</>
)
}

export default UserForm
67 changes: 67 additions & 0 deletions src/pages/manager/planner/ReduxTesting.tsx
Original file line number Diff line number Diff line change
@@ -141,6 +141,73 @@ const ShiftTesting = () => {
return content
}

const UserTesting = () => {
const {
data: dataUsers,
isLoading,
isSuccess,
isError,
error,
} = useGetUsersQuery('EUC')

const [openCard, setOpenCard] = React.useState<boolean>(false)
const [selectedUserId, setSelectedUserId] = React.useState<
string | undefined
>()

const handleClick = (event: React.MouseEvent<unknown>, id: string) => {
console.log('UserId: ', id)
setSelectedUserId(id)
setOpenCard(true)
}

React.useEffect(() => {
if (isSuccess) {
console.log('Users Entity: ', dataUsers)
}
if (isError) {
console.log('Error: ', error)
}
}, [isSuccess, dataUsers, isError, error])

React.useEffect(() => {
if (selectedUserId) {
console.log('Selected User: ', selectedUserId)
}
}, [selectedUserId])

let content = null
if (isLoading) {
content = <Box>is Loading...</Box>
} else if (isError) {
content = <React.Fragment>is Error...</React.Fragment>
} else if (isSuccess) {
content = (
<React.Fragment>
<NewUserCardTest userId={selectedUserId} />
<SortedTable
ids={dataUsers.ids as EntityId[]}
entities={
dataUsers?.entities as Dictionary<
User & { [key in keyof User]: string | number }
>
}
headCells={userHeadCells}
isCheckable={false}
isSortable={true}
handleRowClick={handleClick}
/>
<EditUserCardTest
userId={selectedUserId}
setOpen={setOpenCard}
open={openCard}
/>
</React.Fragment>
)
}
return content
}

const ReduxTesting = () => {
return (
<React.Fragment>
Loading