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

Andrei/shift schedule new #63

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
65 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
d369ddb
minor changes to interface
andreisito Mar 2, 2023
7e34f9b
all schedules
andreisito Mar 4, 2023
19c0aa5
fixing apiSlice errors
gregoriiaaa Mar 4, 2023
50bf0eb
hold up
gregoriiaaa Mar 4, 2023
b464713
npm i
gregoriiaaa Mar 6, 2023
5a8ead0
switched to entries, general table, search bar weird
andreisito 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
817f7da
Merge branch 'dev/main' of github.com:calblueprint/berkeley-student-c…
andreisito 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
20176f7
stuff from devmain
andreisito Mar 11, 2023
5ea3caf
Merge branch 'dev/main' of github.com:calblueprint/berkeley-student-c…
andreisito Mar 11, 2023
5de310e
Merge branch 'dev/main' of github.com:calblueprint/berkeley-student-c…
andreisito Mar 11, 2023
36472f9
updated according to new redux stuff. ready for testing
andreisito 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
fixed the filtering for unassigned users
christianjc committed Mar 1, 2023
commit b7a3bcd52570f2ee6a3b2e252d86e9dedd429805
109 changes: 0 additions & 109 deletions src/pages/manager/planner/NewUnassignedTabContent.tsx

This file was deleted.

156 changes: 68 additions & 88 deletions src/pages/manager/planner/UnassignedTabContent.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import { MenuItem, Select, SelectChangeEvent } from '@mui/material'
import { useEffect, useState } from 'react'
import UnassignedShiftList from '../../../components/ManagerComponents/UnassignedShiftsList/UnassignedShiftsList'
// import UnassignedShiftList from '../../../components/ManagerComponents/UnassignedShiftsList/UnassignedShiftsList'
import SortedTable from '../../../components/shared/tables/SortedTable'
import { useUserContext } from '../../../context/UserContext'
import { getAllShifts } from '../../../firebase/queries/shift'
// import { getAllShifts } from '../../../firebase/queries/shift'
import { HeadCell, Shift } from '../../../interfaces/interfaces'
import { useGetShiftsQuery } from '../../../store/apiSlices/shiftApiSlice'
import { useDispatch, useSelector } from '@reduxjs/toolkit'
import { EntityId, Dictionary } from '@reduxjs/toolkit'

const headCells: HeadCell<Shift>[] = [
{
id: 'name',
isNumeric: false,
label: 'Shift Name',
isSortable: true,
},
{
id: 'timeWindowDisplay',
isNumeric: true,
label: 'Time',
isSortable: false,
},
{
id: 'hours',
isNumeric: true,
label: 'Value',
isSortable: true,
},
]
const headCells: HeadCell<Shift & { [key in keyof Shift]: string | number }>[] =
[
{
id: 'name',
isNumeric: false,
label: 'Shift Name',
isSortable: true,
},
{
id: 'timeWindowDisplay',
isNumeric: true,
label: 'Time',
isSortable: false,
},
{
id: 'hours',
isNumeric: true,
label: 'Value',
isSortable: true,
},
]

const filters = [
'all',
@@ -42,94 +43,73 @@ const filters = [

export const UnassignedTabContent = () => {
const { house } = useUserContext()
const { data, isLoading, isSuccess, isError, error } =
useGetShiftsQuery('EUC')
const { data, isLoading, isSuccess, isError } = useGetShiftsQuery(
house?.houseID
)

const [shifts, setShifts] = useState<Shift[] | undefined>([])
const [displayShifts, setDisplayShifts] = useState<Shift[] | undefined>(
const [shifts, setShifts] = useState<EntityId[] | undefined>([])
const [displayShifts, setDisplayShifts] = useState<EntityId[] | undefined>(
shifts
)
const [filterBy, setFilterBy] = useState<string>(filters[0])

function formatMilitaryTime(militaryTime: number): string {
const hour = Math.floor(militaryTime / 100)
const minute = militaryTime % 100
const isPM = hour >= 12

// Convert hour to 12-hour format
const formattedHour = hour % 12 === 0 ? 12 : hour % 12

// Add leading zero to minute if needed
const formattedMinute = minute < 10 ? `0${minute}` : `${minute}`

// Add AM/PM indicator
const ampm = isPM ? 'PM' : 'AM'

// Return formatted time string
return `${formattedHour}:${formattedMinute}${ampm}`
}

const handleFilterChange = (event: SelectChangeEvent) => {
console.log(event.target.value)
setFilterBy(event.target.value)
}

// runs when the component mounts and when the house changes
// ALL the shifts (unfiltered)
useEffect(() => {
async function fetchShifts() {
const response = await getAllShifts(house.houseID)
if (!response) {
setShifts([])
} else {
// format data here before setting the data (in this case, shifts)
setShifts(
response
.filter((shift) => {
return shift.usersAssigned?.length == 0
})
.map((shift) => {
const time1 = formatMilitaryTime(shift.timeWindow[0])
const time2 = formatMilitaryTime(shift.timeWindow[1])
shift.timeWindowDisplay = time1 + ' - ' + time2
shift.id = shift.shiftID
return shift
})
if (isSuccess && data) {
setShifts(
data.ids?.filter(
(id: EntityId) => data.entities[id]?.usersAssigned?.length === 0
)
}
)
}
fetchShifts()
}, [house])
}, [isSuccess, data])

// runs when the component mounts and when filterBy or shifts changes
// the filtered shifts (filtered by day)
useEffect(() => {
console.log('Changing filters')

setDisplayShifts(
filterBy === filters[0]
? shifts
: shifts?.filter((shift) =>
shift.possibleDays
: shifts?.filter((shiftId) =>
data?.entities[shiftId]?.possibleDays
.map((day) => day.toLocaleLowerCase())
.includes(filterBy)
)
)
}, [filterBy, shifts])
}, [filterBy, shifts, data])

return (
<>
{/* <UnassignedShiftList /> */}
<Select value={filterBy} onChange={handleFilterChange}>
{filters.map((day) => (
<MenuItem key={day} value={day}>
{day}
</MenuItem>
))}
</Select>
<SortedTable
data={displayShifts}
headCells={headCells}
isCheckable={false}
/>
</>
)
if (isLoading) {
return <div>Loading...</div>
} else if (isError) {
return <div>Error</div>
} else {
return (
<>
{/* <UnassignedShiftList /> */}
<Select value={filterBy} onChange={handleFilterChange}>
{filters.map((day) => (
<MenuItem key={day} value={day}>
{day}
</MenuItem>
))}
</Select>
<SortedTable
data={displayShifts as EntityId[]}
entities={
data?.entities as Dictionary<
Shift & { [key in keyof Shift]: string | number }
>
}
headCells={headCells}
isCheckable={false}
/>
</>
)
}
}
2 changes: 1 addition & 1 deletion src/pages/manager/planner/index.tsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { useState } from 'react'
import CategoriesView from '../categoryDropdown/categoriesView'
import { useUserContext } from '../../../context/UserContext'
import ShiftSchedule from '../../../components/ManagerComponents/shiftSchedule/ShiftSchedule'
import { UnassignedTabContent } from './NewUnassignedTabContent'
import { UnassignedTabContent } from './UnassignedTabContent'
import Testing from './Testing'

interface TabPanelProps {