mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Add user feedback to user info and subjects page
This commit is contained in:
parent
1a46945d1e
commit
a3b3bd887f
3 changed files with 42 additions and 2 deletions
|
@ -17,7 +17,7 @@ if (__DEV__) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch this on if you wanna run production URLs while in development
|
// Switch this on if you wanna run production URLs while in development
|
||||||
let use_production = false;
|
let use_production = true;
|
||||||
if (use_production) {
|
if (use_production) {
|
||||||
backendURL = "https://stude.keannu1.duckdns.org";
|
backendURL = "https://stude.keannu1.duckdns.org";
|
||||||
backendURLWebsocket = "ws://stude.keannu1.duckdns.org";
|
backendURLWebsocket = "ws://stude.keannu1.duckdns.org";
|
||||||
|
|
|
@ -39,6 +39,7 @@ import { RootState } from "../../features/redux/Store/Store";
|
||||||
export default function SubjectsPage() {
|
export default function SubjectsPage() {
|
||||||
const logged_in_user = useSelector((state: RootState) => state.user.user);
|
const logged_in_user = useSelector((state: RootState) => state.user.user);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const [feedback, setFeedback] = useState("");
|
||||||
// User Info
|
// User Info
|
||||||
const [user, setUser] = useState({
|
const [user, setUser] = useState({
|
||||||
first_name: "",
|
first_name: "",
|
||||||
|
@ -70,6 +71,9 @@ export default function SubjectsPage() {
|
||||||
});
|
});
|
||||||
setSelectedSubjects(data[1].subjects);
|
setSelectedSubjects(data[1].subjects);
|
||||||
},
|
},
|
||||||
|
onError: () => {
|
||||||
|
setFeedback("Unable to query user info");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationFn: PatchUserInfo,
|
mutationFn: PatchUserInfo,
|
||||||
|
@ -77,6 +81,7 @@ export default function SubjectsPage() {
|
||||||
queryClient.invalidateQueries({ queryKey: ["user"] });
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
||||||
queryClient.invalidateQueries({ queryKey: ["subjects"] });
|
queryClient.invalidateQueries({ queryKey: ["subjects"] });
|
||||||
setSelectedSubjects([]);
|
setSelectedSubjects([]);
|
||||||
|
setFeedback("Changes applied successfully");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -100,6 +105,9 @@ export default function SubjectsPage() {
|
||||||
setSubjects(subjects);
|
setSubjects(subjects);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onError: () => {
|
||||||
|
setFeedback("Unable to query subject info");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Profile photo
|
// Profile photo
|
||||||
|
@ -178,8 +186,10 @@ export default function SubjectsPage() {
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text style={styles.text_white_small}>Save Change</Text>
|
<Text style={styles.text_white_small}>Save Changes</Text>
|
||||||
</Button>
|
</Button>
|
||||||
|
<View style={styles.padding} />
|
||||||
|
<Text style={styles.text_white_small}>{feedback}</Text>
|
||||||
</View>
|
</View>
|
||||||
</AnimatedContainerNoScroll>
|
</AnimatedContainerNoScroll>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -44,6 +44,7 @@ export default function UserInfoPage() {
|
||||||
const logged_in_user = useSelector((state: RootState) => state.user.user);
|
const logged_in_user = useSelector((state: RootState) => state.user.user);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const [feedback, setFeedback] = useState("");
|
||||||
// User Info
|
// User Info
|
||||||
const [user, setUser] = useState({
|
const [user, setUser] = useState({
|
||||||
first_name: "",
|
first_name: "",
|
||||||
|
@ -79,14 +80,21 @@ export default function UserInfoPage() {
|
||||||
setSelectedYearLevel(data[1].year_level);
|
setSelectedYearLevel(data[1].year_level);
|
||||||
dispatch(setUserinState(data[1]));
|
dispatch(setUserinState(data[1]));
|
||||||
},
|
},
|
||||||
|
onError: () => {
|
||||||
|
setFeedback("Unable to query user info");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationFn: PatchUserInfo,
|
mutationFn: PatchUserInfo,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ["user"] });
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
||||||
queryClient.invalidateQueries({ queryKey: ["subjects"] });
|
queryClient.invalidateQueries({ queryKey: ["subjects"] });
|
||||||
|
setFeedback("Changes applied successfully");
|
||||||
dispatch(setUserinState(user));
|
dispatch(setUserinState(user));
|
||||||
},
|
},
|
||||||
|
onError: () => {
|
||||||
|
setFeedback("An error has occured\nChanges have not been saved");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Semester
|
// Semester
|
||||||
|
@ -105,6 +113,9 @@ export default function UserInfoPage() {
|
||||||
// Update the 'semesters' state
|
// Update the 'semesters' state
|
||||||
setSemesters(semestersData);
|
setSemesters(semestersData);
|
||||||
},
|
},
|
||||||
|
onError: () => {
|
||||||
|
setFeedback("Unable to query semester info");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Year Level
|
// Year Level
|
||||||
|
@ -121,6 +132,9 @@ export default function UserInfoPage() {
|
||||||
}));
|
}));
|
||||||
setYearLevels(year_levels);
|
setYearLevels(year_levels);
|
||||||
},
|
},
|
||||||
|
onError: () => {
|
||||||
|
setFeedback("Unable to query year level info");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Course
|
// Course
|
||||||
|
@ -137,6 +151,9 @@ export default function UserInfoPage() {
|
||||||
}));
|
}));
|
||||||
setCourses(courses);
|
setCourses(courses);
|
||||||
},
|
},
|
||||||
|
onError: () => {
|
||||||
|
setFeedback("Unable to query course info");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Profile photo
|
// Profile photo
|
||||||
|
@ -179,6 +196,7 @@ export default function UserInfoPage() {
|
||||||
e: NativeSyntheticEvent<TextInputChangeEventData>
|
e: NativeSyntheticEvent<TextInputChangeEventData>
|
||||||
): void => {
|
): void => {
|
||||||
setUser({ ...user, first_name: e.nativeEvent.text });
|
setUser({ ...user, first_name: e.nativeEvent.text });
|
||||||
|
setFeedback("");
|
||||||
}}
|
}}
|
||||||
value={user.first_name}
|
value={user.first_name}
|
||||||
/>
|
/>
|
||||||
|
@ -195,6 +213,7 @@ export default function UserInfoPage() {
|
||||||
e: NativeSyntheticEvent<TextInputChangeEventData>
|
e: NativeSyntheticEvent<TextInputChangeEventData>
|
||||||
): void => {
|
): void => {
|
||||||
setUser({ ...user, last_name: e.nativeEvent.text });
|
setUser({ ...user, last_name: e.nativeEvent.text });
|
||||||
|
setFeedback("");
|
||||||
}}
|
}}
|
||||||
value={user.last_name}
|
value={user.last_name}
|
||||||
/>
|
/>
|
||||||
|
@ -216,6 +235,9 @@ export default function UserInfoPage() {
|
||||||
setCourseOpen(false);
|
setCourseOpen(false);
|
||||||
}}
|
}}
|
||||||
setValue={setSelectedYearLevel}
|
setValue={setSelectedYearLevel}
|
||||||
|
onChangeValue={() => {
|
||||||
|
setFeedback("");
|
||||||
|
}}
|
||||||
placeholder={user.year_level}
|
placeholder={user.year_level}
|
||||||
placeholderStyle={{
|
placeholderStyle={{
|
||||||
...styles.text_white_tiny_bold,
|
...styles.text_white_tiny_bold,
|
||||||
|
@ -251,6 +273,9 @@ export default function UserInfoPage() {
|
||||||
setCourseOpen(false);
|
setCourseOpen(false);
|
||||||
}}
|
}}
|
||||||
setValue={setSelectedSemester}
|
setValue={setSelectedSemester}
|
||||||
|
onChangeValue={() => {
|
||||||
|
setFeedback("");
|
||||||
|
}}
|
||||||
placeholder={user.semester}
|
placeholder={user.semester}
|
||||||
placeholderStyle={{
|
placeholderStyle={{
|
||||||
...styles.text_white_tiny_bold,
|
...styles.text_white_tiny_bold,
|
||||||
|
@ -286,6 +311,9 @@ export default function UserInfoPage() {
|
||||||
setCourseOpen(open);
|
setCourseOpen(open);
|
||||||
}}
|
}}
|
||||||
setValue={setSelectedCourse}
|
setValue={setSelectedCourse}
|
||||||
|
onChangeValue={() => {
|
||||||
|
setFeedback("");
|
||||||
|
}}
|
||||||
placeholder={user.course}
|
placeholder={user.course}
|
||||||
placeholderStyle={{
|
placeholderStyle={{
|
||||||
...styles.text_white_tiny_bold,
|
...styles.text_white_tiny_bold,
|
||||||
|
@ -337,6 +365,8 @@ export default function UserInfoPage() {
|
||||||
>
|
>
|
||||||
<Text style={styles.text_white_small}>Save Changes</Text>
|
<Text style={styles.text_white_small}>Save Changes</Text>
|
||||||
</Button>
|
</Button>
|
||||||
|
<View style={styles.padding} />
|
||||||
|
<Text style={styles.text_white_small}>{feedback}</Text>
|
||||||
</View>
|
</View>
|
||||||
</AnimatedContainerNoScroll>
|
</AnimatedContainerNoScroll>
|
||||||
</View>
|
</View>
|
||||||
|
|
Loading…
Reference in a new issue