-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from ocftw/feature/add-redux-store-and-wizard
- Loading branch information
Showing
51 changed files
with
1,536 additions
and
1,129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client' | ||
import { useRef } from 'react' | ||
import { Provider } from 'react-redux' | ||
import { makeStore, AppStore } from '../lib/store' | ||
|
||
export default function StoreProvider({ | ||
children | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
const storeRef = useRef<AppStore>() | ||
if (!storeRef.current) { | ||
// Create the store instance the first time this renders | ||
storeRef.current = makeStore() | ||
} | ||
|
||
return <Provider store={storeRef.current}>{children}</Provider> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/webapp/src/components/ActionBoard/ActionBoard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react'; | ||
import { Button, Toolbar } from "@mui/material"; | ||
import { Dispatch, createSelector } from "@reduxjs/toolkit"; | ||
import { Page, hasNextPage, isPageCancellable, wizardActions } from '@/lib/reducers/wizard'; | ||
import { connect } from 'react-redux'; | ||
import { selectWizard } from '@/lib/selector'; | ||
|
||
enum ActionName { | ||
CREATE_PROJECT = 'CREATE_PROJECT', | ||
RECRUIT = 'RECRUIT', | ||
CONTRIBUTE_JOINED_PROJECTS = 'CONTRIBUTE_JOINED_PROJECTS', | ||
CONTRIBUTE_OWNED_PROJECTS = 'CONTRIBUTE_OWNED_PROJECTS', | ||
REMOVE_AND_REFILL_JOBS = 'REMOVE_AND_REFILL_JOBS', | ||
MIRROR = 'MIRROR', | ||
} | ||
|
||
const getPagesByActionName = (name: ActionName): Page[] => { | ||
switch (name) { | ||
case ActionName.CREATE_PROJECT: | ||
return [ | ||
{ | ||
isCancellable: true, | ||
requiredSteps: { | ||
'player--hand--project': { | ||
type: 'player--hand--project', | ||
limit: 1, | ||
} | ||
}, | ||
toggledSteps: [], | ||
}, | ||
{ | ||
isCancellable: true, | ||
requiredSteps: { | ||
'table--active-job': { | ||
type: 'table--active-job', | ||
limit: 1, | ||
} | ||
}, | ||
toggledSteps: [], | ||
}, | ||
]; | ||
default: | ||
return []; | ||
} | ||
} | ||
|
||
interface StateProps { | ||
showCancelBtn: boolean; | ||
showConfirmBtn: boolean; | ||
showSubmitBtn: boolean; | ||
} | ||
|
||
interface DispatchProps { | ||
onCreateProjectActionClick: () => void; | ||
onConfirmBtnClick: () => void; | ||
onCancelBtnClick: () => void; | ||
onSubmitBtnClick: () => void; | ||
} | ||
|
||
type Props = StateProps & DispatchProps; | ||
|
||
const ActionBoard: React.FC<Props> = ({ showCancelBtn, showConfirmBtn, showSubmitBtn, onCancelBtnClick, onConfirmBtnClick, onSubmitBtnClick }) => { | ||
return ( | ||
<Toolbar> | ||
{showCancelBtn && <Button onClick={onCancelBtnClick}> Cancel </Button>} | ||
{showConfirmBtn && <Button onClick={onConfirmBtnClick}>Confirm</Button>} | ||
{showSubmitBtn && <Button onClick={onSubmitBtnClick}>Submit</Button>} | ||
</Toolbar> | ||
) | ||
} | ||
|
||
const mapStateToProps = createSelector( | ||
selectWizard, (wizard): StateProps => { | ||
const showCancelBtn = isPageCancellable(wizard); | ||
const showConfirmBtn = hasNextPage(wizard); | ||
const showSubmitBtn = !hasNextPage(wizard); | ||
return { | ||
showCancelBtn, | ||
showConfirmBtn, | ||
showSubmitBtn, | ||
} | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch) => { | ||
const onCreateProjectActionClick = () => { | ||
dispatch(wizardActions.init(getPagesByActionName(ActionName.CREATE_PROJECT))); | ||
} | ||
const onConfirmBtnClick = () => { | ||
dispatch(wizardActions.nextPage()); | ||
} | ||
const onCancelBtnClick = () => { | ||
dispatch(wizardActions.prevPage()); | ||
} | ||
const onSubmitBtnClick = () => { | ||
dispatch(wizardActions.clear()); | ||
} | ||
return { | ||
onCreateProjectActionClick, | ||
onConfirmBtnClick, | ||
onCancelBtnClick, | ||
onSubmitBtnClick, | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(ActionBoard); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/webapp/src/components/DevActions/ContributionValueInputBox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Box, Stack, TextField } from "@mui/material"; | ||
import React from "react"; | ||
|
||
interface Props { | ||
value: number; | ||
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
const ContributionValueInputBox: React.FC<Props> = ({ value, onChange }) => ( | ||
<Stack direction="row" spacing={2}> | ||
<Box component='label'>Value</Box> | ||
<TextField | ||
type="number" | ||
InputProps={{ inputProps: { min: 0, max: 5 } }} | ||
value={value} | ||
onChange={onChange} | ||
/> | ||
</Stack> | ||
); | ||
|
||
export default ContributionValueInputBox; |
Oops, something went wrong.