added the front API function to tranform guest account into regular account and added translations

This commit is contained in:
Clément Le Bihan
2023-04-11 22:26:21 +02:00
parent 9033fbe937
commit 1c76266444
6 changed files with 83 additions and 24 deletions
+8
View File
@@ -146,6 +146,14 @@ export default class API {
return response.access_token;
}
public static async transformGuestToUser(registrationInput: RegistrationInput): Promise<void> {
await API.fetch({
route: "/auth/me",
body: registrationInput,
method: "PUT",
});
}
/***
* Retrieve information of the currently authentified user
*/
+56
View File
@@ -119,6 +119,25 @@ export const en = {
SettingsCategoryEmail: 'Email',
SettingsCategoryGoogle: 'Google',
SettingsCategoryPiano: 'Piano',
SettingsCategoryGuest: 'Guest',
transformGuestToUserExplanations: 'You can transform your guest account to a user account by providing a username and a password. You will then be able to save your progress and access your profile.',
SettingsNotificationsPushNotifications: 'Push',
SettingsNotificationsEmailNotifications: 'Email',
SettingsNotificationsTrainingReminder: 'Training reminder',
SettingsNotificationsReleaseAlert: 'Release alert',
dataCollection: 'Data collection',
customAds: 'Custom ads',
recommendations: 'Recommendations',
SettingsPreferencesTheme: 'Theme',
SettingsPreferencesLanguage: 'Language',
SettingsPreferencesDifficulty: 'Difficulty',
SettingsPreferencesColorblindMode: 'Colorblind mode',
SettingsPreferencesMicVolume: 'Mic volume',
SettingsPreferencesDevice: 'Device',
};
export const fr: typeof en = {
@@ -238,6 +257,25 @@ export const fr: typeof en = {
SettingsCategoryEmail: 'Email',
SettingsCategoryGoogle: 'Google',
SettingsCategoryPiano: 'Piano',
transformGuestToUserExplanations: 'Vous êtes actuellement connecté en tant qu\'invité. Vous pouvez créer un compte pour sauvegarder vos données et profiter de toutes les fonctionnalités de Chromacase.',
SettingsCategoryGuest: 'Invité',
SettingsNotificationsEmailNotifications: 'Email',
SettingsNotificationsPushNotifications: 'Notifications push',
SettingsNotificationsReleaseAlert: 'Alertes de nouvelles Sorties',
SettingsNotificationsTrainingReminder: 'Rappel d\'entrainement',
SettingsPreferencesColorblindMode: 'Mode daltonien',
SettingsPreferencesDevice: 'Appareil',
SettingsPreferencesDifficulty: 'Difficulté',
SettingsPreferencesLanguage: 'Langue',
SettingsPreferencesTheme: 'Thème',
SettingsPreferencesMicVolume: 'Volume du micro',
dataCollection: 'Collecte de données',
recommendations: 'Recommandations',
customAds: 'Publicités personnalisées',
};
export const sp: typeof en = {
@@ -360,4 +398,22 @@ export const sp: typeof en = {
SettingsCategorySecurity: 'Seguridad',
SettingsCategoryEmail: 'Email',
SettingsCategoryGoogle: 'Google',
transformGuestToUserExplanations: 'Actualmente estás conectado como invitado. Puedes crear una cuenta para guardar tus datos y disfrutar de todas las funciones de Chromacase.',
SettingsCategoryGuest: 'Invitado',
SettingsNotificationsEmailNotifications: 'Email',
SettingsNotificationsPushNotifications: 'Notificaciones push',
SettingsNotificationsReleaseAlert: 'Alertas de nuevas Sorties',
SettingsNotificationsTrainingReminder: 'Recordatorio de entrenamiento',
SettingsPreferencesColorblindMode: 'Modo daltoniano',
SettingsPreferencesDevice: 'Dispositivo',
SettingsPreferencesDifficulty: 'Dificultad',
SettingsPreferencesLanguage: 'Idioma',
SettingsPreferencesTheme: 'Tema',
SettingsPreferencesMicVolume: 'Volumen del micrófono',
dataCollection: 'Recopilación de datos',
recommendations: 'Recomendaciones',
customAds: 'Anuncios personalizados',
};
+8 -12
View File
@@ -1,38 +1,34 @@
import React from "react";
import SignUpForm from "../../components/forms/signupform";
import { Center } from "native-base";
import { Center, Heading, Text } from "native-base";
import API, { APIError } from "../../API";
import { translate } from "../../i18n/i18n";
import { useDispatch } from "../../state/Store";
import { setAccessToken } from "../../state/UserSlice";
const handleSubmit = async (
username: string,
password: string,
email: string,
apiSetter: (token: string) => void
email: string
) => {
let res: string;
try {
res = await API.createAccount({ username, password, email });
await API.transformGuestToUser({ username, password, email });
} catch (error) {
if (error instanceof APIError) return translate(error.userMessage);
if (error instanceof Error) return error.message;
return translate("unknownError");
}
apiSetter(res);
return translate("loggedIn");
};
const GuestToUserView = () => {
const dispatch = useDispatch();
return (
<Center flex={1} justifyContent={"center"}>
<Heading>{translate("signUp")}</Heading>
<Text mt={5} mb={10}>
{translate("transformGuestToUserExplanations")}
</Text>
<SignUpForm
onSubmit={(username, password, email) =>
handleSubmit(username, password, email, (token) =>
dispatch(setAccessToken(token))
)
handleSubmit(username, password, email)
}
/>
</Center>
+4 -4
View File
@@ -40,7 +40,7 @@ const NotificationsView = ({ navigation }) => {
elements={[
{
type: "toggle",
title: "Push notifications",
title: translate("SettingsNotificationsPushNotifications"),
data: {
value: pushNotifications,
onToggle: () => {
@@ -55,7 +55,7 @@ const NotificationsView = ({ navigation }) => {
},
{
type: "toggle",
title: "Email notifications",
title: translate("SettingsNotificationsEmailNotifications"),
data: {
value: emailNotifications,
onToggle: () => {
@@ -70,7 +70,7 @@ const NotificationsView = ({ navigation }) => {
},
{
type: "toggle",
title: "Training reminder",
title: translate("SettingsNotificationsTrainingReminder"),
data: {
value: trainingReminder,
onToggle: () => {
@@ -85,7 +85,7 @@ const NotificationsView = ({ navigation }) => {
},
{
type: "toggle",
title: "New songs",
title: translate("SettingsNotificationsReleaseAlert"),
data: {
value: releaseAlert,
onToggle: () => {
+6 -7
View File
@@ -43,7 +43,7 @@ const PreferencesView = ({ navigation }) => {
elements={[
{
type: "dropdown",
title: "Theme",
title: translate("SettingsPreferencesTheme"),
data: {
value: settings.colorScheme,
defaultValue: "system",
@@ -61,7 +61,7 @@ const PreferencesView = ({ navigation }) => {
},
{
type: "dropdown",
title: "Language",
title: translate("SettingsPreferencesLanguage"),
data: {
value: language,
defaultValue: DefaultLanguage,
@@ -71,14 +71,13 @@ const PreferencesView = ({ navigation }) => {
options: [
{ label: "Français", value: "fr" },
{ label: "English", value: "en" },
{ label: "Italiano", value: "it" },
{ label: "Espanol", value: "sp" },
],
},
},
{
type: "dropdown",
title: "Difficulty",
title: translate("SettingsPreferencesDifficulty"),
data: {
value: settings.preferedLevel,
defaultValue: "medium",
@@ -103,7 +102,7 @@ const PreferencesView = ({ navigation }) => {
elements={[
{
type: "toggle",
title: "Color blind mode",
title: translate("SettingsPreferencesColorblindMode"),
data: {
value: settings.colorBlind,
onToggle: () => {
@@ -122,7 +121,7 @@ const PreferencesView = ({ navigation }) => {
elements={[
{
type: "range",
title: "Mic volume",
title: translate("SettingsPreferencesMicVolume"),
data: {
value: settings.micLevel,
min: 0,
@@ -135,7 +134,7 @@ const PreferencesView = ({ navigation }) => {
},
{
type: "dropdown",
title: "Device",
title: translate("SettingsPreferencesDevice"),
data: {
value: settings.preferedInputName || "0",
defaultValue: "0",
+1 -1
View File
@@ -231,7 +231,7 @@ const ProfileSettings = ({ navigation }: { navigation: any }) => {
</Button>
<Button
onPress={() => {
navigation.navigate("SignUp");
navigation.navigate("GuestToUser");
}}
colorScheme="green"
>