Skip to content

Commit

Permalink
feat: twu proposal polling
Browse files Browse the repository at this point in the history
  • Loading branch information
IanFonzie committed Dec 6, 2023
1 parent 1c525bc commit 996c1e0
Showing 1 changed file with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { TWU_PROPOSAL_EVALUATION_CONTENT_ID } from "front-end/config";
import {
PROPOSAL_POLL_DURATION,
TWU_PROPOSAL_EVALUATION_CONTENT_ID
} from "front-end/config";
import { makeStartLoading, makeStopLoading } from "front-end/lib";
import { Route } from "front-end/lib/app/types";
import * as SubmitProposalTerms from "front-end/lib/components/submit-proposal-terms";
Expand Down Expand Up @@ -51,7 +54,8 @@ type ModalId =
| "saveChangesAndSubmit"
| "withdrawBeforeDeadline"
| "withdrawAfterDeadline"
| "delete";
| "delete"
| "orgProposalChangeDetected";

export interface State extends Tab.Params {
organizations: OrganizationSlim[];
Expand Down Expand Up @@ -114,7 +118,9 @@ export type InnerMsg =
| ADT<
"onDeleteResponse",
api.ResponseValidation<TWUProposal, DeleteValidationErrors>
>;
>
| ADT<"checkStatus">
| ADT<"onCheckStatusResponse", api.ResponseValidation<TWUProposal, string[]>>;

export type Msg = component_.page.Msg<InnerMsg, Route>;

Expand Down Expand Up @@ -295,7 +301,10 @@ const update: component_.base.Update<State, Msg> = ({ state, msg }) => {
result.value,
result.value.status === TWUProposalStatus.Draft
);
return [newState.set("isEditing", true), cmds];
return [
newState.set("isEditing", true),
[...cmds, component_.cmd.dispatch(adt("checkStatus") as Msg)]
];
}
case "cancelEditing": {
const [newState, cmds] = resetProposal(state, state.proposal);
Expand Down Expand Up @@ -681,6 +690,46 @@ const update: component_.base.Update<State, Msg> = ({ state, msg }) => {
]
];
}
case "checkStatus": {
return [
state,
state.isEditing
? [
api.proposals.twu.readOne<Msg>(state.proposal.opportunity.id)(
state.proposal.id,
(result) => adt("onCheckStatusResponse", result)
)
]
: []
];
}
case "onCheckStatusResponse": {
const incomingProposal = api.getValidValue(msg.value, null);
if (!incomingProposal) {
return [state, []];
}

if (incomingProposal.updatedAt > state.proposal.updatedAt) {
return [
state,
[
component_.cmd.dispatch(
adt("showModal", "orgProposalChangeDetected" as const) as Msg
)
]
];
}

return [
state,
[
component_.cmd.delayedDispatch(
PROPOSAL_POLL_DURATION,
adt("checkStatus") as Msg
)
]
];
}
default:
return [state, []];
}
Expand Down Expand Up @@ -911,6 +960,32 @@ export const component: Tab.Component<State, Msg> = {
}
]
});
case "orgProposalChangeDetected":
return component_.page.modal.show({
title: "Proposal Changes Detected",
body: () => (
<>
<p>
Someone else in your organization has submitted changes to this
proposal since you started editing it.
</p>
<p>Your options are:</p>
<ol>
<li>
Save your changes to a document offline, cancel editing, and
re-enter your changes.
</li>
<li>
Keep working, and when you submit, your version{" "}
<strong>will</strong> overwrite the previously submitted
changes.
</li>
</ol>
</>
),
onCloseMsg: adt("hideModal") as Msg,
actions: []
});
case null:
return component_.page.modal.hide();
}
Expand Down

0 comments on commit 996c1e0

Please sign in to comment.