Skip to content

Commit

Permalink
Renamed the useModal hook returns to match the props. Added a server …
Browse files Browse the repository at this point in the history
…commit handler in the list controller.
  • Loading branch information
buchananwill committed Apr 13, 2024
1 parent f1de069 commit dc584be
Show file tree
Hide file tree
Showing 23 changed files with 155 additions and 104 deletions.
8 changes: 4 additions & 4 deletions app/contexts/color/subject-color-coding-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function SubjectColorCodingProvider({

const modalInitialState = { ...useColorState(defaultColorState) };

const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();

const handleColorConfirm = (updatedColorStateValue: ColorState) => {
setSubjectColorCoding(() => {
Expand All @@ -48,15 +48,15 @@ export default function SubjectColorCodingProvider({
value={{
setModalText: setLessonText,
openModal: openModal,
onCancel: closeModal,
onClose: closeModal,
onCancel: onClose,
onClose: onClose,
onConfirm: handleColorConfirm,
stringKey: lessonText,
...modalInitialState
}}
>
{children}
<ColorSelectModal show={isOpen} initialState={modalInitialState}>
<ColorSelectModal show={show} initialState={modalInitialState}>
{lessonText}
</ColorSelectModal>
</ModalColorSelectContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function WriteableStringMapContextProvider<T>({
mapKeyAccessor
);

const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();

async function handleCommit() {
if (commitServerAction === undefined) return;
Expand Down Expand Up @@ -92,14 +92,14 @@ export function WriteableStringMapContextProvider<T>({
<UnsavedChangesModal
unsavedChanges={unsavedChanges}
handleOpen={() => openModal()}
show={isOpen}
onClose={closeModal}
show={show}
onClose={onClose}
onConfirm={() => {
closeModal();
onClose();
handleCommit();
}}
onCancel={() => {
closeModal();
onClose();
}}
>
<p>Commit updated models to the database?</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function BundleEditor({

const [activeTab, setActiveTab] = useState(0);

const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();

const activeBundleAndId = useMemo(() => {
function getActiveBundleAndId() {
Expand Down Expand Up @@ -168,15 +168,15 @@ export function BundleEditor({
payload: { key: id.toString(), data: immerBundle }
});
dispatchWithoutControl(true);
closeModal();
onClose();
};
const handleCancel = () => {
const { stateBundle } = activeBundleAndId;
dispatchRenameLocally({
contextKey: contextKeyMemo,
update: stateBundle.name
});
closeModal();
onClose();
};

const handleOpen = () => {
Expand Down Expand Up @@ -280,8 +280,8 @@ export function BundleEditor({

<RenameModal
contextKey={contextKeyMemo}
show={isOpen}
onClose={closeModal}
show={show}
onClose={onClose}
onConfirm={handleRenameBundle}
onCancel={handleCancel}
enterToConfirm={true}
Expand Down
10 changes: 5 additions & 5 deletions app/curriculum/delivery-models/add-new-curriculum-model-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function AddNewCurriculumModelCard({
alreadyUnsaved: boolean;
yearGroup: number;
}) {
const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();
const { workTaskTypeMap } = useWorkTaskTypeContext();
const { dispatch, curriculumModelsMap } = useCurriculumModelContext();
const [newModelTaskType, setNewModelTaskType] =
Expand Down Expand Up @@ -102,7 +102,7 @@ export function AddNewCurriculumModelCard({
setNewModelTaskType(
taskTypeSelectionList.length > 0 ? taskTypeSelectionList[0] : null
);
closeModal();
onClose();
};

const handleAddNewModel = () => {
Expand All @@ -124,7 +124,7 @@ export function AddNewCurriculumModelCard({
});
dispatchWithoutControl(false);
setRevertUnsaved(true);
closeModal();
onClose();
appRouterInstance.refresh();
};

Expand All @@ -141,8 +141,8 @@ export function AddNewCurriculumModelCard({
</Button>
</Card>
<ConfirmActionModal
show={isOpen}
onClose={closeModal}
show={show}
onClose={onClose}
onConfirm={handleAddNewModel}
onCancel={handleCancel}
title={'Add New Curriculum Model'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function BundleAssignmentsProvider({
false
);

const { openModal, isOpen, closeModal } = useModal();
const { openModal, show, onClose } = useModal();
const { bundleItemsMap } = useBundleItemsContext();

const handleConfirm = () => {
Expand All @@ -75,11 +75,11 @@ export function BundleAssignmentsProvider({
});
}
});
closeModal();
onClose();
};

const handleCancel = () => {
closeModal();
onClose();
};

return (
Expand All @@ -102,8 +102,8 @@ export function BundleAssignmentsProvider({
</div>
)}
<ConfirmActionModal
show={isOpen}
onClose={closeModal}
show={show}
onClose={onClose}
onConfirm={handleConfirm}
onCancel={handleCancel}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function BundleItemsContextProvider({
initialValue: StaticDeletedBundleList
});

const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();

const handleConfirm = () => {
startTransition(() => {
Expand Down Expand Up @@ -97,7 +97,7 @@ export function BundleItemsContextProvider({
.then(() => {
dispatch({ type: 'updateAll', payload: updatedBundles });
setUnsavedBundles({ contextKey: UnsavedBundleEdits, update: false });
closeModal();
onClose();
});
});
};
Expand All @@ -116,8 +116,8 @@ export function BundleItemsContextProvider({
<UnsavedChangesModal
unsavedChanges={unsaved}
handleOpen={openModal}
show={isOpen}
onClose={closeModal}
show={show}
onClose={onClose}
onConfirm={handleConfirm}
onCancel={handleCancel}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function CurriculumModelsContextProvider({
const CurriculumModelsReducer = StringMapReducer<WorkProjectSeriesSchemaDto>;
const [currentModels, dispatch] = useReducer(CurriculumModelsReducer, models);

const { isOpen, openModal, closeModal } = useModal();
const { show, openModal, onClose } = useModal();
const { currentState: unsavedChanges, dispatchUpdate: setUnsaved } =
useSelectiveContextControllerBoolean(
UnsavedCurriculumModelChanges,
Expand Down Expand Up @@ -96,7 +96,7 @@ export function CurriculumModelsContextProvider({
}
})
.finally(clearFlag);
closeModal();
onClose();
}

return (
Expand All @@ -121,10 +121,10 @@ export function CurriculumModelsContextProvider({
</div>
)}
<ConfirmActionModal
show={isOpen}
onClose={closeModal}
show={show}
onClose={onClose}
onConfirm={handleCommit}
onCancel={closeModal}
onCancel={onClose}
>
<p>Commit updated models to the database?</p>
</ConfirmActionModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useRenameCurriculumDeliveryModel(
false
);

const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();
const renameModalContextKey = useSelectiveContextKeyMemo(
`${RenameModalWrapperContextKey}:${modelId}`,
listenerKey
Expand Down Expand Up @@ -71,23 +71,23 @@ export function useRenameCurriculumDeliveryModel(
}

dispatchWithoutControl(true);
closeModal();
onClose();
};

const handleCancelRename = () => {
dispatchUpdate({
contextKey: renameModalContextKey,
update: curriculumModelsMap[modelId]?.name
});
closeModal();
onClose();
};

const renameModalProps: RenameModalProps & ConfirmActionModalProps = {
contextKey: renameModalContextKey,
onConfirm: handleConfirmRename,
onCancel: handleCancelRename,
onClose: closeModal,
show: isOpen,
onClose: onClose,
show: show,
error: error
};

Expand Down
10 changes: 5 additions & 5 deletions app/electives/[carouselGroupId]/rotate-carousel-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function RotateCarouselButton({
useContext(ElectiveContext);
const { showTooltips } = useContext(TooltipsContext);
const dispatch = useContext(ElectiveDispatchContext);
const { isOpen, openModal, closeModal } = useModal();
const { show, openModal, onClose } = useModal();
const [rotationNumber, setRotationNumber] = useState(0);

const [showError, setShowError] = useState(false);
Expand Down Expand Up @@ -126,14 +126,14 @@ export function RotateCarouselButton({
</TooltipContent>
</Tooltip>
<ConfirmActionModal
show={isOpen}
onClose={() => closeModal()}
show={show}
onClose={() => onClose()}
onConfirm={() => {
handleRotationConfirm(rotationNumber);
closeModal();
onClose();
}}
onCancel={() => {
closeModal();
onClose();
}}
>
{filterType == 'all' ? (
Expand Down
10 changes: 5 additions & 5 deletions app/electives/commit-changes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CommitChanges = ({ children }: Props) => {
const [commitPending, setCommitPending] = useState(false);

const { showTooltips } = useContext(TooltipsContext);
let { isOpen, closeModal, openModal } = useModal();
let { show, onClose, openModal } = useModal();
const electiveState = useContext(ElectiveContext);
const [enabled, setEnabled] = useState(false);
const { modifiedPreferences } = electiveState;
Expand Down Expand Up @@ -90,14 +90,14 @@ const CommitChanges = ({ children }: Props) => {
</TooltipContent>
</Tooltip>
<ConfirmActionModal
show={isOpen}
onClose={closeModal}
show={show}
onClose={onClose}
onConfirm={() => {
closeModal();
onClose();
handleCommitClick();
}}
onCancel={() => {
closeModal();
onClose();
}}
>
<p>Commit changes to the database</p>
Expand Down
8 changes: 4 additions & 4 deletions app/generic/components/color/color-coding-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ColorCodingProvider({

const modalInitialState = { ...useColorState(defaultColorState) };

const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();

const handleColorConfirm = (updatedColorStateValue: ColorState) => {
setColorCoding(() => {
Expand All @@ -45,12 +45,12 @@ export default function ColorCodingProvider({
stringKey: stringKey,
openModal: openModal,
onConfirm: handleColorConfirm,
onCancel: () => closeModal(),
onClose: closeModal
onCancel: () => onClose(),
onClose: onClose
}}
>
{children}
<ColorSelectModal show={isOpen} initialState={modalInitialState}>
<ColorSelectModal show={show} initialState={modalInitialState}>
{stringKey}
</ColorSelectModal>
</ModalColorSelectContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion app/generic/components/modals/confirm-action-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useModal() {
setIsOpen(true);
}, []);

return { isOpen, closeModal, openModal };
return { show: isOpen, onClose: closeModal, openModal };
}

export interface ConfirmActionModalProps {
Expand Down
10 changes: 5 additions & 5 deletions app/generic/hooks/use-rating-edit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useRatingEditModal<R, E>({
const [modalRatingValue, setModalRatingValue] = useState(0);
const [ratingInModal, setRatingInModal] = useState<R>();
const [elementInModal, setProviderInModal] = useState<E>();
const { isOpen, closeModal, openModal } = useModal();
const { show, onClose, openModal } = useModal();

const triggerModal = useCallback(
({ elementWithRating, rating }: { rating: R; elementWithRating: E }) => {
Expand All @@ -40,15 +40,15 @@ export function useRatingEditModal<R, E>({
}, []);

return {
show: isOpen,
show: show,
onConfirm: () => {
if (isNotUndefined(ratingInModal) && isNotUndefined(elementInModal)) {
confirmRatingValue(ratingInModal, elementInModal, modalRatingValue);
}
closeModal();
onClose();
},
onCancel: () => closeModal(),
onClose: () => closeModal(),
onCancel: () => onClose(),
onClose: () => onClose(),
elementWithRatingsInModal: elementInModal,
modalRatingValue,
ratingInModal,
Expand Down
Loading

0 comments on commit dc584be

Please sign in to comment.