Skip to content

Commit

Permalink
fix: put alert to encourage user to save changes (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmelKun authored Dec 6, 2023
1 parent 3e5cd69 commit f8368ea
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 35 deletions.
2 changes: 1 addition & 1 deletion apps/expo/src/components/modals/AlertModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const AlertModal = ({
Vwidth="24"
Vheight="10"
onPress={onCancel}
isLoading={isLoading}
disabled={isLoading}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { View, Text, TouchableOpacity } from "react-native";
import useGoBack from "../../hooks/useGoBack";
import EditIcon from "../../icons/EditIcon";
import LeftArrowIcon from "../../icons/LeftArrowIcon";
import { Feather } from "@expo/vector-icons";

interface ReviewerHeaderProps {
showEditIcon: boolean;
Expand All @@ -21,7 +21,7 @@ export const ReviewerDetailsHeader = ({
onPress={goBack}
className="flex flex-row items-center self-center"
>
<LeftArrowIcon />
<Feather name="x" size={24} color="black" />
</TouchableOpacity>
<Text className="font-nunito-bold text-2xl leading-[38.40px] text-neutral-800">
Reviewer Details
Expand Down
28 changes: 21 additions & 7 deletions apps/expo/src/forms/CreateTestForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const CreateTestForm: FC<Props> = ({
const [selectedReviewer, setSelectedReviewer] = useState<Reviewer | null>(
null,
);

const [openAlert, setOpenAlert] = useState(false);
const [isBottomSheetOpen, setBottomSheetOpen] = useState(false);
const [errorInAIQuestion, setErrorInAIQuestion] = useState(false);
Expand Down Expand Up @@ -252,7 +251,11 @@ const CreateTestForm: FC<Props> = ({
}, [image, testDetails?.image]);

const handleExitScreen = () => {
if (isDirty || questions.length > 0) {
if (
(testTitle === "Create Test" && isDirty) ||
(testTitle === "Edit Test" && isDirty) ||
questions.length > 0
) {
setOpenAlert(true);
} else {
goBack();
Expand All @@ -261,7 +264,11 @@ const CreateTestForm: FC<Props> = ({

useEffect(() => {
const backAction = () => {
if (isDirty || questions.length > 0) {
if (
(testTitle === "Create Test" && isDirty) ||
(testTitle === "Edit Test" && isDirty) ||
questions.length > 0
) {
setOpenAlert(true);
} else {
goBack();
Expand Down Expand Up @@ -440,7 +447,13 @@ const CreateTestForm: FC<Props> = ({
screenName={testTitle}
optionIcon={<Octicons name="three-bars" size={24} color="black" />}
onIconPress={() => setIsSidebarOpen(true)}
backIcon={<Feather name="x" size={24} color="black" />}
backIcon={
questions.length > 0 || testTitle === "Create Test" ? (
<Feather name="x" size={24} color="black" />
) : (
""
)
}
handleExit={handleExitScreen}
showDeleteIcon={testTitle === "Edit Test"}
onDeletePress={() =>
Expand Down Expand Up @@ -776,17 +789,18 @@ const CreateTestForm: FC<Props> = ({

<AlertModal
isVisible={openAlert}
alertTitle={"Are you sure?"}
alertTitle={"Save your test?"}
alertDescription={
"You will lose all unsaved progress if you exit this screen"
"You will lose all unsaved changes if you exit this screen"
}
confirmButtonText={"Yes"}
isCancelButtonVisible={true}
cancelButtonText={"Cancel"}
onCancel={() => {
setOpenAlert(false);
}}
onConfirm={goBack}
isLoading={isCreatingQuiz}
onConfirm={handleSubmit(submitForm)}
/>
</SafeAreaView>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/src/screens/create-collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const CreateCollection = () => {
isVisible={openAlert}
alertTitle={"Are you sure?"}
alertDescription={
"You will lose all unsaved progress if you exit this screen"
"You will lose all unsaved changes if you exit this screen"
}
confirmButtonText={"Yes"}
isCancelButtonVisible={true}
Expand Down
61 changes: 40 additions & 21 deletions apps/expo/src/screens/create-question/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const CreateQuestionScreen: FC = () => {
const [choices, setChoices] = useState<Choice[]>([]);
const [isDeleting, setIsDeleting] = useState(false);
const [isChoiceModalTouched, setIsChoiceModalTouched] = useState(false);
const [promptSaveModal, setPromptSaveModal] = useState(false);

const { height, width } = Dimensions.get("window");

Expand Down Expand Up @@ -190,6 +191,7 @@ export const CreateQuestionScreen: FC = () => {
const snapPoints = useMemo(() => ["5%", "25%", "70%"], []);

const openBottomSheet = () => {
handleSaveQuestion();
bottomSheetRef.current?.expand();
};

Expand Down Expand Up @@ -569,12 +571,7 @@ export const CreateQuestionScreen: FC = () => {
};

const handleExitScreen = () => {
if (question?.inEdit) {
setOpenAlert(true);
} else {
resetQuestionImage();
goBack();
}
setOpenAlert(true);
};

const handleDelete = () => {
Expand Down Expand Up @@ -979,33 +976,55 @@ export const CreateQuestionScreen: FC = () => {
</View>
</ScrollView>

<BottomSheet
ref={bottomSheetRef}
index={-1}
snapPoints={snapPoints}
onChange={handleSheetChanges}
style={styles.bottomSheetContainer}
>
<ChoiceBottomSheet
goToCreateQuestion={goToCreateQuestion}
closeBottomSheet={() => bottomSheetRef.current?.close()}
/>
</BottomSheet>
<AlertModal
isVisible={promptSaveModal}
alertTitle={"Save your question?"}
alertDescription={
"You will lose all unsaved changes if you exit this screen"
}
confirmButtonText={"Yes"}
isCancelButtonVisible={true}
cancelButtonText={"Cancel"}
onCancel={() => {
setPromptSaveModal(false);
}}
onConfirm={handleSaveAnswer(() => {
setIsSaved(false);
setPromptSaveModal(false);
})}
/>

<AlertModal
isVisible={openAlert}
alertTitle={"Are you sure?"}
alertTitle={"Save your question?"}
alertDescription={
"You will lose all unsaved progress if you exit this screen"
"You will lose all unsaved changes if you exit this screen"
}
confirmButtonText={"Yes"}
isCancelButtonVisible={true}
cancelButtonText={"Cancel"}
onCancel={() => {
setOpenAlert(false);
}}
onConfirm={goBack}
onConfirm={() => {
handleSaveQuestion();
resetQuestionImage();
goBack();
}}
/>

<BottomSheet
ref={bottomSheetRef}
index={-1}
snapPoints={snapPoints}
onChange={handleSheetChanges}
style={styles.bottomSheetContainer}
>
<ChoiceBottomSheet
goToCreateQuestion={goToCreateQuestion}
closeBottomSheet={() => bottomSheetRef.current?.close()}
/>
</BottomSheet>
</View>
</SafeAreaView>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/src/screens/create-reviewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ export const CreateReviewerScreen = ({
isVisible={openAlert}
alertTitle={"Are you sure?"}
alertDescription={
"You will lose all unsaved progress if you exit this screen"
"You will lose all unsaved changes if you exit this screen"
}
confirmButtonText={"Yes"}
isCancelButtonVisible={true}
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/src/screens/edit-collection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export const EditCollection: FC<RootStackScreenProps<"EditCollection">> = ({
isVisible={openAlert}
alertTitle={"Are you sure?"}
alertDescription={
"You will lose all unsaved progress if you exit this screen"
"You will lose all unsaved changes if you exit this screen"
}
confirmButtonText={"Yes"}
isCancelButtonVisible={true}
Expand Down
2 changes: 1 addition & 1 deletion apps/expo/src/screens/edit-personal-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const EditPersonalInfoScreen = () => {
isVisible={openAlert}
alertTitle={"Are you sure?"}
alertDescription={
"You will lose all unsaved progress if you exit this screen"
"You will lose all unsaved changes if you exit this screen"
}
confirmButtonText={"Yes"}
isCancelButtonVisible={true}
Expand Down

0 comments on commit f8368ea

Please sign in to comment.