Refactor providers call
This commit is contained in:
		@@ -8,9 +8,7 @@ import {
 | 
			
		||||
} from "@mui/material";
 | 
			
		||||
import React, { PropsWithChildren } from "react";
 | 
			
		||||
 | 
			
		||||
interface AlertContext {
 | 
			
		||||
  alert: (message: string, title?: string) => Promise<void>;
 | 
			
		||||
}
 | 
			
		||||
type AlertContext = (message: string, title?: string) => Promise<void>;
 | 
			
		||||
 | 
			
		||||
const AlertContextK = React.createContext<AlertContext | null>(null);
 | 
			
		||||
 | 
			
		||||
@@ -29,16 +27,14 @@ export function AlertDialogProvider(p: PropsWithChildren): React.ReactElement {
 | 
			
		||||
    cb.current = null;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const hook: AlertContext = {
 | 
			
		||||
    alert: (message, title) => {
 | 
			
		||||
      setTitle(title);
 | 
			
		||||
      setMessage(message);
 | 
			
		||||
      setOpen(true);
 | 
			
		||||
  const hook: AlertContext = (message, title) => {
 | 
			
		||||
    setTitle(title);
 | 
			
		||||
    setMessage(message);
 | 
			
		||||
    setOpen(true);
 | 
			
		||||
 | 
			
		||||
      return new Promise((res) => {
 | 
			
		||||
        cb.current = res;
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
    return new Promise((res) => {
 | 
			
		||||
      cb.current = res;
 | 
			
		||||
    });
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
 
 | 
			
		||||
@@ -8,13 +8,11 @@ import {
 | 
			
		||||
} from "@mui/material";
 | 
			
		||||
import React, { PropsWithChildren } from "react";
 | 
			
		||||
 | 
			
		||||
interface ConfirmContext {
 | 
			
		||||
  confirm: (
 | 
			
		||||
    message: string,
 | 
			
		||||
    title?: string,
 | 
			
		||||
    confirmButton?: string
 | 
			
		||||
  ) => Promise<boolean>;
 | 
			
		||||
}
 | 
			
		||||
type ConfirmContext = (
 | 
			
		||||
  message: string,
 | 
			
		||||
  title?: string,
 | 
			
		||||
  confirmButton?: string
 | 
			
		||||
) => Promise<boolean>;
 | 
			
		||||
 | 
			
		||||
const ConfirmContextK = React.createContext<ConfirmContext | null>(null);
 | 
			
		||||
 | 
			
		||||
@@ -38,17 +36,15 @@ export function ConfirmDialogProvider(
 | 
			
		||||
    cb.current = null;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const hook: ConfirmContext = {
 | 
			
		||||
    confirm: (message, title, confirmButton) => {
 | 
			
		||||
      setTitle(title);
 | 
			
		||||
      setMessage(message);
 | 
			
		||||
      setConfirmButton(confirmButton);
 | 
			
		||||
      setOpen(true);
 | 
			
		||||
  const hook: ConfirmContext = (message, title, confirmButton) => {
 | 
			
		||||
    setTitle(title);
 | 
			
		||||
    setMessage(message);
 | 
			
		||||
    setConfirmButton(confirmButton);
 | 
			
		||||
    setOpen(true);
 | 
			
		||||
 | 
			
		||||
      return new Promise((res) => {
 | 
			
		||||
        cb.current = res;
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
    return new Promise((res) => {
 | 
			
		||||
      cb.current = res;
 | 
			
		||||
    });
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ export function CreateFamilyDialog(p: {
 | 
			
		||||
      await FamilyApi.CreateFamily(name);
 | 
			
		||||
      setName("");
 | 
			
		||||
      p.onCreated();
 | 
			
		||||
      await alert.alert("La famille a été créée avec succès !");
 | 
			
		||||
      await alert("La famille a été créée avec succès !");
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      console.error(e);
 | 
			
		||||
      setError(true);
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ export function JoinFamilyDialog(p: {
 | 
			
		||||
        case JoinFamilyResult.Success:
 | 
			
		||||
          setCode("");
 | 
			
		||||
          p.onJoined();
 | 
			
		||||
          await alert.alert("La famille a été rejointe avec succès !");
 | 
			
		||||
          await alert("La famille a été rejointe avec succès !");
 | 
			
		||||
          break;
 | 
			
		||||
 | 
			
		||||
        case JoinFamilyResult.TooManyRequests:
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ export function DeleteAccountRoute(): React.ReactElement {
 | 
			
		||||
  const doDelete = async () => {
 | 
			
		||||
    try {
 | 
			
		||||
      if (
 | 
			
		||||
        !(await confirm.confirm(
 | 
			
		||||
        !(await confirm(
 | 
			
		||||
          "Voulez-vous vraiment supprimer votre compte ?",
 | 
			
		||||
          undefined,
 | 
			
		||||
          "Supprimer mon compte"
 | 
			
		||||
@@ -35,12 +35,12 @@ export function DeleteAccountRoute(): React.ReactElement {
 | 
			
		||||
      await UserApi.DeleteAccount(token);
 | 
			
		||||
      AuthApi.RemoveAuthToken();
 | 
			
		||||
 | 
			
		||||
      await alert.alert("Votre compte a été supprimé avec succès !");
 | 
			
		||||
      await alert("Votre compte a été supprimé avec succès !");
 | 
			
		||||
 | 
			
		||||
      navigate("/");
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      console.error(e);
 | 
			
		||||
      alert.alert("Echec de la suppression du compte !");
 | 
			
		||||
      alert("Echec de la suppression du compte !");
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -189,7 +189,7 @@ function FamilyCard(p: {
 | 
			
		||||
    try {
 | 
			
		||||
      if (
 | 
			
		||||
        !p.f.CanLeave ||
 | 
			
		||||
        !(await confirm.confirm(
 | 
			
		||||
        !(await confirm(
 | 
			
		||||
          "Voulez-vous vraiment quitter la famille " + p.f.name + " ?"
 | 
			
		||||
        ))
 | 
			
		||||
      )
 | 
			
		||||
@@ -199,12 +199,12 @@ function FamilyCard(p: {
 | 
			
		||||
 | 
			
		||||
      p.onFamilyLeft();
 | 
			
		||||
 | 
			
		||||
      alert.alert(
 | 
			
		||||
      alert(
 | 
			
		||||
        `La famille ${p.f.name} a été retirée de votre liste de familles !`
 | 
			
		||||
      );
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      console.error(e);
 | 
			
		||||
      alert.alert("Echec du retrait de la famille !");
 | 
			
		||||
      alert("Echec du retrait de la famille !");
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -255,7 +255,7 @@ function DeleteAccountButton(): React.ReactElement {
 | 
			
		||||
  const requestDelete = async () => {
 | 
			
		||||
    try {
 | 
			
		||||
      if (
 | 
			
		||||
        !(await confirm.confirm(
 | 
			
		||||
        !(await confirm(
 | 
			
		||||
          "Voulez-vous initier la suppression de votre compte ?",
 | 
			
		||||
          "Suppression de compte"
 | 
			
		||||
        ))
 | 
			
		||||
@@ -264,12 +264,12 @@ function DeleteAccountButton(): React.ReactElement {
 | 
			
		||||
 | 
			
		||||
      await UserApi.RequestAccountDeletion();
 | 
			
		||||
 | 
			
		||||
      await alert.alert(
 | 
			
		||||
      await alert(
 | 
			
		||||
        "Demande de suppression de compte enregistrée avec succès. Veuillez consulter votre boîte mail."
 | 
			
		||||
      );
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      console.error(e);
 | 
			
		||||
      alert.alert("Echec de la demande de suppression de compte !");
 | 
			
		||||
      alert("Echec de la demande de suppression de compte !");
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,7 @@
 | 
			
		||||
import CancelIcon from "@mui/icons-material/Close";
 | 
			
		||||
import DeleteIcon from "@mui/icons-material/DeleteOutlined";
 | 
			
		||||
import EditIcon from "@mui/icons-material/Edit";
 | 
			
		||||
import SaveIcon from "@mui/icons-material/Save";
 | 
			
		||||
import {
 | 
			
		||||
  DataGrid,
 | 
			
		||||
  GridActionsCellItem,
 | 
			
		||||
@@ -9,17 +13,12 @@ import {
 | 
			
		||||
import React from "react";
 | 
			
		||||
import { FamilyApi, FamilyUser } from "../../api/FamilyApi";
 | 
			
		||||
import { useAlert } from "../../context_providers/AlertDialogProvider";
 | 
			
		||||
import { useConfirm } from "../../context_providers/ConfirmDialogProvider";
 | 
			
		||||
import { AsyncWidget } from "../../widgets/AsyncWidget";
 | 
			
		||||
import { useUser } from "../../widgets/BaseAuthenticatedPage";
 | 
			
		||||
import { useFamily } from "../../widgets/BaseFamilyRoute";
 | 
			
		||||
import { FamilyPageTitle } from "../../widgets/FamilyPageTitle";
 | 
			
		||||
import { TimeWidget } from "../../widgets/TimeWidget";
 | 
			
		||||
import AddIcon from "@mui/icons-material/Add";
 | 
			
		||||
import EditIcon from "@mui/icons-material/Edit";
 | 
			
		||||
import DeleteIcon from "@mui/icons-material/DeleteOutlined";
 | 
			
		||||
import SaveIcon from "@mui/icons-material/Save";
 | 
			
		||||
import CancelIcon from "@mui/icons-material/Close";
 | 
			
		||||
import { useConfirm } from "../../context_providers/ConfirmDialogProvider";
 | 
			
		||||
 | 
			
		||||
export function FamilyUsersListRoute(): React.ReactElement {
 | 
			
		||||
  const family = useFamily();
 | 
			
		||||
@@ -79,7 +78,7 @@ function UsersTable(p: {
 | 
			
		||||
    try {
 | 
			
		||||
      const user = p.users.find((u) => u.user_id === id)!;
 | 
			
		||||
      if (
 | 
			
		||||
        !(await confirm.confirm(
 | 
			
		||||
        !(await confirm(
 | 
			
		||||
          `Voulez-vous vraiment retirer ${user.user_name} de cette famille ?`
 | 
			
		||||
        ))
 | 
			
		||||
      )
 | 
			
		||||
@@ -89,7 +88,7 @@ function UsersTable(p: {
 | 
			
		||||
      p.onReload();
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      console.error(e);
 | 
			
		||||
      alert.alert("Echec de la suppression de l'utilisateur !");
 | 
			
		||||
      alert("Echec de la suppression de l'utilisateur !");
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
@@ -186,7 +185,7 @@ function UsersTable(p: {
 | 
			
		||||
      }}
 | 
			
		||||
      onProcessRowUpdateError={(e) => {
 | 
			
		||||
        console.error(e);
 | 
			
		||||
        alert.alert("Échec de la mise à jour des informations utilisateurs !");
 | 
			
		||||
        alert("Échec de la mise à jour des informations utilisateurs !");
 | 
			
		||||
      }}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
 
 | 
			
		||||
@@ -65,7 +65,7 @@ export function BaseFamilyRoute(): React.ReactElement {
 | 
			
		||||
  const changeInvitationCode = async () => {
 | 
			
		||||
    try {
 | 
			
		||||
      if (
 | 
			
		||||
        !(await confirm.confirm(
 | 
			
		||||
        !(await confirm(
 | 
			
		||||
          "Voulez-vous vraiment générer un nouveau code d'invitation pour cette famille ? Cette action aura pour effet d'invalider l'ancien code !"
 | 
			
		||||
        ))
 | 
			
		||||
      )
 | 
			
		||||
@@ -78,7 +78,7 @@ export function BaseFamilyRoute(): React.ReactElement {
 | 
			
		||||
      onReload();
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      console.error(e);
 | 
			
		||||
      alert.alert("Echec du renouvellement du code d'invitation !");
 | 
			
		||||
      alert("Echec du renouvellement du code d'invitation !");
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user