Skip to content

Commit

Permalink
feat: cancel drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
IanFonzie committed Oct 19, 2024
1 parent 8e51a04 commit 13551a9
Showing 1 changed file with 71 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface EvaluationScore {
notes: Immutable<LongText.State>;
}

type ModalId = ADT<"cancel">;
type ModalId = ADT<"cancelDraft">;

export interface State extends Tab.Params {
showModal: ModalId | null;
Expand All @@ -75,6 +75,8 @@ export interface State extends Tab.Params {
export type InnerMsg =
| ADT<"toggleAccordion", number>
| ADT<"showModal", ModalId>
| ADT<"hideModal">
| ADT<"cancel">
| ADT<"saveDraft">
| ADT<
"onSaveDraftResponse",
Expand Down Expand Up @@ -212,6 +214,36 @@ const update: component_.base.Update<State, Msg> = ({ state, msg }) => {
}),
[]
];
case "showModal":
return [state.set("showModal", msg.value), []];
case "hideModal":
if (state.saveLoading > 0) {
return [state, []];
}
return [state.set("showModal", null), []];
case "cancel":
return [
state,
[
component_.cmd.dispatch(
component_.global.newRouteMsg(
adt("opportunitySWUEdit" as const, {
opportunityId: state.opportunity.id,
tab: (() => {
switch (state.proposal.status) {
case SWUProposalStatus.TeamQuestionsPanelIndividual:
return "overview" as const;
case SWUProposalStatus.TeamQuestionsPanelConsensus:
return "consensus" as const;
default:
return "teamQuestions" as const;
}
})()
})
)
)
]
];
case "saveDraft": {
const scores = getValues(state);
if (scores === null) {
Expand Down Expand Up @@ -828,6 +860,14 @@ function isValid(state: Immutable<State>): boolean {
);
}

// component_.page.Component<
// RouteParams,
// SharedState,
// State,
// InnerMsg,
// Route
// >

export const component: Tab.Component<State, Msg> = {
init,
update,
Expand All @@ -837,61 +877,35 @@ export const component: Tab.Component<State, Msg> = {
return component_.page.readyMsg();
},

// getModal: (state) => {
// const isEnterScoreLoading = state.enterScoreLoading > 0;
// const valid = isValid(state);
// switch (state.showModal) {
// case "enterScore":
// return component_.page.modal.show({
// title: "Enter Score",
// onCloseMsg: adt("hideModal") as Msg,
// actions: [
// {
// text: "Submit Score",
// icon: "star-full",
// color: "primary",
// button: true,
// loading: isEnterScoreLoading,
// disabled: isEnterScoreLoading || !valid,
// msg: adt("submitScore")
// },
// {
// text: "Cancel",
// color: "secondary",
// disabled: isEnterScoreLoading,
// msg: adt("hideModal")
// }
// ],
// body: (dispatch) => (
// <div>
// <p>
// Provide a score for each team question response submitted by the
// proponent.
// </p>
// {state.scores.map((s, i) => {
// return (
// <NumberField.view
// key={`swu-proposal-question-score-field-${i}`}
// extraChildProps={{ suffix: "point(s)" }}
// required
// disabled={isEnterScoreLoading}
// label={`Question ${i + 1} Score`}
// placeholder="Score"
// dispatch={component_.base.mapDispatch(
// dispatch,
// (v) => adt("scoreMsg" as const, [i, v]) as Msg
// )}
// state={s}
// />
// );
// })}
// </div>
// )
// });
// case null:
// return component_.page.modal.hide();
// }
// },
getModal: (state) => {
if (!state.showModal) {
return component_.page.modal.hide();
}
switch (state.showModal.tag) {
case "cancelDraft":
return component_.page.modal.show<Msg>({
title: "Cancel New Sprint With Us Evaluation?",
body: () =>
"Are you sure you want to cancel? Any information you may have entered will be lost if you do so.",
onCloseMsg: adt("hideModal"),
actions: [
{
text: "Yes, I want to cancel",
color: "danger",
msg: adt("cancel"),
button: true
},
{
text: "Go Back",
color: "secondary",
msg: adt("hideModal")
}
]
});
case null:
return component_.page.modal.hide();
}
},

getActions: ({ state, dispatch }) => {
const proposal = state.proposal;
Expand Down Expand Up @@ -940,7 +954,7 @@ export const component: Tab.Component<State, Msg> = {
color: "c-nav-fg-alt",
disabled: isSaveLoading,
onClick: () =>
dispatch(adt("showModal", adt("cancel")) as Msg)
dispatch(adt("showModal", adt("cancelDraft")) as Msg)
}
]
);
Expand Down

0 comments on commit 13551a9

Please sign in to comment.