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
setting up Redux and RTK Query. I have set up the redux store and I a…
…m working on seting up the createApi slide for the project
christianjc committed Feb 28, 2023

Verified

This commit was signed with the committer’s verified signature.
macalinao Ian Macalinao
commit e5b807318051be87fb1209741f3db35307540272
696 changes: 465 additions & 231 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -17,15 +17,20 @@
"@mui/material": "^5.10.16",
"@mui/styled-engine-sc": "^5.10.16",
"@mui/x-data-grid": "^5.17.14",
"@reduxjs/toolkit": "^1.9.3",
"@types/papaparse": "^5.3.5",
"firebase": "^9.10.0",
"fs": "^0.0.1-security",
"next": "^13.1.6",
"next-redux-wrapper": "^8.1.0",
"papaparse": "^5.3.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-firebase-hooks": "^5.1.1",
"react-redux": "^8.0.5",
"react-select": "^5.5.6",
"react-uuid": "^2.0.0",
"redux-firestore": "^1.0.0",
"styled-components": "^5.3.6"
},
"devDependencies": {
47 changes: 39 additions & 8 deletions src/firebase/clientApp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Import the functions you need from the SDKs you need
import { initializeApp } from 'firebase/app'
import { Analytics, getAnalytics } from 'firebase/analytics'
import { Firestore, getFirestore } from 'firebase/firestore'
import { Auth, getAuth } from 'firebase/auth'

const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
@@ -15,17 +15,48 @@ const firebaseConfig = {

// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig)
let analytics: Analytics, firestore: Firestore // TYPES!! Imported from Firebase!
if (firebaseConfig?.projectId) {
// Initialize Firebase
const app = initializeApp(firebaseConfig)
let analytics: Analytics, firestore: Firestore, auth: Auth // TYPES!! Imported from Firebase!

if (app.name && typeof window !== 'undefined') {
analytics = getAnalytics(app) // HOVER OVER GETANALYTICS FOR RETURN TYPE
if (firebaseConfig?.projectId) {
if (firebaseApp.name && typeof window !== 'undefined') {
analytics = getAnalytics(firebaseApp) // HOVER OVER GETANALYTICS FOR RETURN TYPE
}

// Access Firebase services using shorthand notation
firestore = getFirestore(firebaseApp) // HOVER OVER GETFIREBASE FOR RETURN TYPE
auth = getAuth(firebaseApp)
}

export { firestore, analytics }
export { firestore, analytics, auth }

// // Import the functions you need from the SDKs you need
// import { initializeApp } from 'firebase/app'
// import { Analytics, getAnalytics } from 'firebase/analytics'
// import { Firestore, getFirestore } from 'firebase/firestore'

// const firebaseConfig = {
// apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
// authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
// projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
// storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
// messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
// appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
// measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
// }

// // Initialize Firebase
// const firebaseApp = initializeApp(firebaseConfig)
// let analytics: Analytics, firestore: Firestore // TYPES!! Imported from Firebase!
// if (firebaseConfig?.projectId) {
// // Initialize Firebase
// const app = initializeApp(firebaseConfig)

// if (app.name && typeof window !== 'undefined') {
// analytics = getAnalytics(app) // HOVER OVER GETANALYTICS FOR RETURN TYPE
// }

// // Access Firebase services using shorthand notation
// firestore = getFirestore(firebaseApp) // HOVER OVER GETFIREBASE FOR RETURN TYPE
// }

// export { firestore, analytics }
12 changes: 8 additions & 4 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -2,12 +2,16 @@ import '../styles/globals.css'
import type { AppProps } from 'next/app'
import { AuthUserProvider } from '../context/UserContext'

import { Provider } from 'react-redux'
import { store } from '../store/store'

function MyApp({ Component, pageProps }: AppProps) {
return (
<AuthUserProvider>
<Component {...pageProps} />
</AuthUserProvider>
<Provider store={store}>
<AuthUserProvider>
<Component {...pageProps} />
</AuthUserProvider>
</Provider>
)
}

export default MyApp
44 changes: 44 additions & 0 deletions src/pages/manager/planner/Testing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import type { RootState } from '../../../store/store'
import { useSelector, useDispatch } from 'react-redux'
import { decrement, increment } from '../../../store/slices/counterSlice'
import { useGetHousesQuery } from '../../../store/api/apiSlice'

const Testing = () => {
const count = useSelector((state: RootState) => state.counter.value)
const { data, isLoading } = useGetHousesQuery('houses/EUC/shifts')
const dispatch = useDispatch()

React.useEffect(() => {
console.log('isLoading =', isLoading)
console.log(data)
}, [isLoading, data])

if (isLoading) {
return <h1>Is Loading...</h1>
} else {
return (
<>
<div>
<div>
<button
aria-label="Increment value"
onClick={() => dispatch(increment())}
>
Increment
</button>
<span>{count}</span>
<button
aria-label="Decrement value"
onClick={() => dispatch(decrement())}
>
Decrement
</button>
</div>
</div>
</>
)
}
}

export default Testing
2 changes: 1 addition & 1 deletion src/pages/manager/planner/UnassignedTabContent.tsx
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ const headCells: HeadCell<Shift>[] = [
},
{
id: 'timeWindowDisplay',
isNumeric: false,
isNumeric: true,
label: 'Time',
isSortable: false,
},
2 changes: 2 additions & 0 deletions src/pages/manager/planner/index.tsx
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import CategoriesView from '../categoryDropdown/categoriesView'
import { useUserContext } from '../../../context/UserContext'
import ShiftSchedule from '../../../components/ManagerComponents/shiftSchedule/ShiftSchedule'
import { UnassignedTabContent } from './UnassignedTabContent'
import Testing from './Testing'

interface TabPanelProps {
children?: React.ReactNode
@@ -66,6 +67,7 @@ export default function SchedulePage() {
</Box>
<TabPanel value={currPage} index={0}>
<UnassignedTabContent />
<Testing />
</TabPanel>
<TabPanel value={currPage} index={1}>
<ShiftSchedule />
155 changes: 155 additions & 0 deletions src/store/api/apiSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import { firestore } from '../../firebase/clientApp'
import {
collection,
doc,
getDocs,
getDoc,
QuerySnapshot,
DocumentSnapshot,
} from 'firebase/firestore'

import { MaybePromise } from '@reduxjs/toolkit/dist/query/tsHelpers'
import { ThunkDispatch } from '@reduxjs/toolkit'

export type BaseQueryFn<
Args = any,
Result = unknown,
Error = unknown,
DefinitionExtraOptions = {},
Meta = {}
> = (
args: Args,
api: BaseQueryApi,
extraOptions: DefinitionExtraOptions
) => MaybePromise<QueryReturnValue<Result, Error, Meta>>

export interface BaseQueryApi {
signal: AbortSignal
abort: (reason?: string) => void
dispatch: ThunkDispatch<any, any, any>
getState: () => unknown
extra: unknown
endpoint: string
type: 'query' | 'mutation'
forced?: boolean
}

export type QueryReturnValue<T = unknown, E = unknown, M = unknown> =
| {
error: E
data?: undefined
meta?: M
}
| {
error?: undefined
data: T
meta?: M
}

const baseQuery = fetchBaseQuery({
baseUrl: 'fakeUrl',
fetchFn: async (input: Request) => {
console.log('ARGS: ', input)
// console.log('ARGS: ', api)

const { url, method } = input
const pathArray = url
.split('fakeUrl')[1]
.split('/')
.filter((p: string) => p.length > 0)

let isCollection = false
console.log(pathArray)
if (pathArray.length === 0) {
return { error: 'Invalid Path' }
}

let path = ''
pathArray.forEach((p: string, index: number) => {
if (pathArray.length === index + 1) {
path += p
} else {
path += p + '/'
}
})

console.log(path)
if (pathArray.length % 2 !== 0) {
isCollection = true
}

const response: { data: unknown; id: string }[] = []
setTimeout(() => {
console.log('waited for 3000ms')
}, 3000)
try {
switch (method) {
case 'GET':
// let snapshot: any
if (isCollection) {
//** If the query is a collection, get the full collection */
const querySnapshot: QuerySnapshot<unknown> = await getDocs(
collection(firestore, path)
)
console.log('collection SnapShot', querySnapshot)
// console.log(querySnapshot.docs)
if (!querySnapshot) return { error: 'collection not found' }
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
const data = doc.data()
response.push({ data: data, id: doc.id.toString() })
console.log(doc.id, ' => ', doc.data())
})
console.log(response)
// return snapshot.map((doc) => ({ id: doc.id, ...doc.data() }))

return new Response(JSON.stringify({ data: response }))
} else {
//** If the query is a document, get the document with id provided */
const snapshot: DocumentSnapshot<unknown> = await getDoc(
doc(firestore, path)
)
if (!snapshot.exists()) {
return { error: 'Document does not exist' }
}
const data = snapshot.data()
response.push({ data: data, id: pathArray[pathArray.length - 1] })
console.log(response)
return new Response(JSON.stringify({ data: response }))
}

// case 'POST':
// await query.add(data)
// return { data, url: '' }
// case 'PUT':
// await query.set(data)
// return { data, url: '' }
// case 'DELETE':
// await query.delete()
// return { data, url: '' }
// break
default:
return null
}
} catch (error) {
console.log(error)
return { error }
}
},
})

export const apiSlice = createApi({
baseQuery,
// tagTypes: ['Shift', 'User'],
endpoints: (builder) => ({
getHouses: builder.query({
query: (path) => ({
url: `${path}`,
method: 'GET',
}),
}),
}),
})

export const { useGetHousesQuery } = apiSlice
35 changes: 35 additions & 0 deletions src/store/slices/counterSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createSlice } from '@reduxjs/toolkit'
import type { PayloadAction } from '@reduxjs/toolkit'

export interface CounterState {
value: number
}

const initialState: CounterState = {
value: 0,
}

export const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment: (state) => {
// Redux Toolkit allows us to write "mutating" logic in reducers. It
// doesn't actually mutate the state because it uses the Immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
state.value += 1
},
decrement: (state) => {
state.value -= 1
},
incrementByAmount: (state, action: PayloadAction<number>) => {
state.value += action.payload
},
},
})

// Action creators are generated for each case reducer function
export const { increment, decrement, incrementByAmount } = counterSlice.actions

export default counterSlice.reducer
18 changes: 18 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { configureStore } from '@reduxjs/toolkit'
import counterReducer from './slices/counterSlice'
import { apiSlice } from './api/apiSlice'

export const store = configureStore({
reducer: {
[apiSlice.reducerPath]: apiSlice.reducer,
counter: counterReducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(apiSlice.middleware),
devTools: process.env.NODE_ENV !== 'production',
})

// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch