diff --git a/front/API.ts b/front/API.ts index 1256628..a12ea98 100644 --- a/front/API.ts +++ b/front/API.ts @@ -61,6 +61,39 @@ const baseAPIUrl = ? "/api" : Constants.manifest?.extra?.apiUrl; +const requestGet = async (url: string) => { + try { + const response = await fetch(url, { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + } + }); + const json = await response.json(); + return json; + } catch (error) { + console.error(error); + } +} + +const requestPost = async (url: string, params: any[]) => { + try { + const response = await fetch(url, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + }, + body : JSON.stringify(params), + }); + const json = await response.json(); + return json; + } catch (error) { + console.error(error); + } +} + export default class API { private static async fetch(params: FetchParams) { const jwtToken = store.getState().user.accessToken; @@ -417,12 +450,20 @@ export default class API { ]; } - static async updateUserCredentials(dataKey: string, value: any): Promise { - let validDataKeys: string = "password email"; + /** + * + * @param dataKey + * @param value + * @description update user's account credentials. Either email or password, you choose via the datakey param + * @returns new user's credentials + */ + + static async updateUserCredentials(dataKey: 'password' | 'email', value: any): Promise { + let validDataKeys: string[] = ['password', 'email']; return new Promise((resolve, reject) => { setTimeout(() => { if (!validDataKeys.includes(dataKey)) - return resolve("giga chad"); + return resolve('giga chad'); }, 1000); }); } diff --git a/front/components/forms/changeEmailForm.tsx b/front/components/forms/changeEmailForm.tsx index fa6a0c6..6ffdf3f 100644 --- a/front/components/forms/changeEmailForm.tsx +++ b/front/components/forms/changeEmailForm.tsx @@ -23,7 +23,7 @@ const validationSchemas = { }; const ChangeEmailForm = ({ onSubmit }: ChangeEmailFormProps) => { - const [formData, setFormData] = React.useState({ + const [formData, setFormData] = React.useState({ oldEmail: { value: "", error: null as string | null, @@ -34,12 +34,12 @@ const ChangeEmailForm = ({ onSubmit }: ChangeEmailFormProps) => { } }); - const [submittingForm, setSubmittingForm] = React.useState(false); + const [submittingForm, setSubmittingForm] = React.useState(false); const toast = useToast(); - return ( - - + return ( + + { { let error: null | string = null; @@ -71,7 +71,7 @@ const ChangeEmailForm = ({ onSubmit }: ChangeEmailFormProps) => { { let error: null | string = null; @@ -86,7 +86,7 @@ const ChangeEmailForm = ({ onSubmit }: ChangeEmailFormProps) => { } > {formData.oldEmail.error} - + - - - ); + + + ); } export default ChangeEmailForm;