diff --git a/src/data/deanApproval.ts b/src/data/deanApproval.ts new file mode 100644 index 0000000..6231196 --- /dev/null +++ b/src/data/deanApproval.ts @@ -0,0 +1,3 @@ +export type DeanApproval = { + +} diff --git a/src/provider/dummy/index.ts b/src/provider/dummy/index.ts index 7466cc3..7e8f58d 100644 --- a/src/provider/dummy/index.ts +++ b/src/provider/dummy/index.ts @@ -1 +1,5 @@ export * from './company' +export * from './edition' +export * from './student' +export * from './internship' +export * from './helpers' diff --git a/src/state/actions/index.ts b/src/state/actions/index.ts index 9959cb5..39de422 100644 --- a/src/state/actions/index.ts +++ b/src/state/actions/index.ts @@ -1,6 +1,7 @@ import { StudentAction, StudentActions } from "@/state/actions/student"; import { EditionAction, EditionActions } from "@/state/actions/edition"; import { SettingActions, SettingsAction } from "@/state/actions/settings"; +import { InternshipProposalAction, InternshipProposalActions } from "@/state/actions/proposal"; import { Dispatch } from "react"; import { useDispatch as useReduxDispatch } from "react-redux"; @@ -9,10 +10,11 @@ export * from "./base" export * from "./edition" export * from "./settings" export * from "./student" +export * from "./proposal" -export type Action = StudentAction | EditionAction | SettingsAction; +export type Action = StudentAction | EditionAction | SettingsAction | InternshipProposalAction; -export const Actions = { ...StudentActions, ...EditionActions, ...SettingActions } +export const Actions = { ...StudentActions, ...EditionActions, ...SettingActions, ...InternshipProposalActions } export type Actions = typeof Actions; export const useDispatch = () => useReduxDispatch>() diff --git a/src/state/actions/proposal.ts b/src/state/actions/proposal.ts new file mode 100644 index 0000000..a7876c4 --- /dev/null +++ b/src/state/actions/proposal.ts @@ -0,0 +1,37 @@ +import { Action } from "@/state/actions/base"; +import { Internship } from "@/data"; + +export enum InternshipProposalActions { + Send = "SEND_PROPOSAL", + Save = "SAVE_PROPOSAL", + Approve = "RECEIVE_PROPOSAL_APPROVE", + Decline = "RECEIVE_PROPOSAL_DECLINE", + Receive = "RECEIVE_PROPOSAL_STATE", +} + +export interface SendProposalAction extends Action { + internship: Internship; +} + +export interface ReceiveProposalApproveAction extends Action { + +} + +export interface ReceiveProposalDeclineAction extends Action { + +} + +export interface ReceiveProposalUpdateAction extends Action { + +} + +export interface SaveProposalAction extends Action { + internship: Internship; +} + +export type InternshipProposalAction + = SendProposalAction + | SaveProposalAction + | ReceiveProposalApproveAction + | ReceiveProposalDeclineAction + | ReceiveProposalUpdateAction; diff --git a/src/state/reducer/index.ts b/src/state/reducer/index.ts index 5d22892..3b9c780 100644 --- a/src/state/reducer/index.ts +++ b/src/state/reducer/index.ts @@ -1,13 +1,15 @@ import { combineReducers } from "redux"; -import studentReducer from "./student" +import studentReducer from "@/state/reducer/student" import editionReducer from "@/state/reducer/edition"; import settingsReducer from "@/state/reducer/settings"; +import internshipProposalReducer from "@/state/reducer/proposal"; const rootReducer = combineReducers({ student: studentReducer, edition: editionReducer, settings: settingsReducer, + proposal: internshipProposalReducer, }) export type AppState = ReturnType; diff --git a/src/state/reducer/proposal.ts b/src/state/reducer/proposal.ts new file mode 100644 index 0000000..c779e70 --- /dev/null +++ b/src/state/reducer/proposal.ts @@ -0,0 +1,53 @@ +import { DeanApproval } from "@/data/deanApproval"; +import { InternshipProposalAction, InternshipProposalActions } from "@/state/actions"; +import { Internship } from "@/data"; + +export type ProposalStatus = "draft" | "awaiting" | "accepted" | "declined"; + +export type InternshipProposalState = { + accepted: boolean; + sent: boolean; + declined: boolean; + requiredDeanApprovals: DeanApproval[]; + proposal: Internship | null; + comment: string | null; +} + +const defaultInternshipProposalState: InternshipProposalState = { + accepted: false, + declined: false, + proposal: null, + requiredDeanApprovals: [], + sent: false, + comment: null +} + +const getInternshipProposalStatus = ({ accepted, declined, sent }: InternshipProposalState): ProposalStatus => { + switch (true) { + case !sent: + return "draft"; + case sent && accepted: + return "accepted" + case sent && declined: + return "declined" + case sent && (!accepted && !declined): + return "awaiting" + default: + throw new Error("Invalid proposal state " + JSON.stringify({ accepted, declined, sent })); + } +} + +const internshipProposalReducer = (state: InternshipProposalState = defaultInternshipProposalState, action: InternshipProposalAction): InternshipProposalState => { + switch (action.type) { + case InternshipProposalActions.Save: + case InternshipProposalActions.Send: + return { + ...state, + proposal: action.internship + } + default: + return state; + } +} + +export default internshipProposalReducer;