3 Commits

Author SHA1 Message Date
79ce616781 Show a feedback when saving couple information
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-31 19:30:16 +02:00
e4a1817d7f Simplify navigation to set member photo 2023-08-31 19:27:14 +02:00
2a69c89065 Automatically trim values before saving 2023-08-31 19:23:21 +02:00
4 changed files with 63 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ import { MemberInput } from "../../widgets/forms/MemberInput";
import { PropSelect } from "../../widgets/forms/PropSelect";
import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton";
import { useQuery } from "../../hooks/useQuery";
import { useLoadingMessage } from "../../hooks/context_providers/LoadingMessageProvider";
/**
* Create a new couple route
@@ -165,7 +166,8 @@ export function FamilyEditCoupleRoute(): React.ReactElement {
const cancel = () => {
setShouldQuit(true);
n(-1);
n(family.family.coupleURL(couple!));
//n(-1);
};
const save = async (c: Couple) => {
@@ -217,6 +219,7 @@ export function CouplePage(p: {
}): React.ReactElement {
const confirm = useConfirm();
const snackbar = useSnackbar();
const loadingMessage = useLoadingMessage();
const family = useFamily();
@@ -230,8 +233,12 @@ export function CouplePage(p: {
setCouple(new Couple(structuredClone(couple)));
};
const save = () => {
p.onSave!(couple);
const save = async () => {
loadingMessage.show(
"Enregistrement des informations du couple en cours..."
);
await p.onSave!(couple);
loadingMessage.hide();
};
const cancel = async () => {

View File

@@ -39,6 +39,7 @@ import { UploadPhotoButton } from "../../widgets/forms/UploadPhotoButton";
import { useQuery } from "../../hooks/useQuery";
import { mdiFamilyTree } from "@mdi/js";
import Icon from "@mdi/react";
import { useLoadingMessage } from "../../hooks/context_providers/LoadingMessageProvider";
/**
* Create a new member route
@@ -185,8 +186,8 @@ export function FamilyEditMemberRoute(): React.ReactElement {
const cancel = () => {
setShouldQuit(true);
//n(family.family.URL(`member/${member!.id}`));
n(-1);
n(family.family.memberURL(member!));
//n(-1);
};
const save = async (m: Member) => {
@@ -241,6 +242,7 @@ export function MemberPage(p: {
}): React.ReactElement {
const confirm = useConfirm();
const snackbar = useSnackbar();
const loadingMessage = useLoadingMessage();
const family = useFamily();
@@ -254,8 +256,12 @@ export function MemberPage(p: {
setMember(new Member(structuredClone(member)));
};
const save = () => {
p.onSave!(member);
const save = async () => {
loadingMessage.show(
"Enregistrement des informations du membre en cours..."
);
await p.onSave!(member);
loadingMessage.hide();
};
const cancel = async () => {

View File

@@ -103,8 +103,29 @@ fn check_opt_str_val(
Ok(())
}
fn trim_opt_val(val: &mut Option<String>) {
if let Some(s) = val {
*val = Some(s.trim().to_string());
}
if val.as_deref() == Some("") {
*val = None;
}
}
impl MemberRequest {
pub async fn to_member(self, member: &mut Member) -> anyhow::Result<()> {
pub async fn to_member(mut self, member: &mut Member) -> anyhow::Result<()> {
// Trim values before processing
trim_opt_val(&mut self.first_name);
trim_opt_val(&mut self.last_name);
trim_opt_val(&mut self.birth_last_name);
trim_opt_val(&mut self.email);
trim_opt_val(&mut self.country);
trim_opt_val(&mut self.address);
trim_opt_val(&mut self.city);
trim_opt_val(&mut self.note);
trim_opt_val(&mut self.phone);
let c = StaticConstraints::default();
check_opt_str_val(
&self.first_name,

View File

@@ -6,6 +6,7 @@ diesel::table! {
family_id -> Int4,
wife -> Nullable<Int4>,
husband -> Nullable<Int4>,
#[max_length = 1]
state -> Nullable<Varchar>,
photo_id -> Nullable<Int4>,
time_create -> Int8,
@@ -23,7 +24,9 @@ diesel::table! {
families (id) {
id -> Int4,
time_create -> Int8,
#[max_length = 30]
name -> Varchar,
#[max_length = 7]
invitation_code -> Varchar,
disable_couple_photos -> Bool,
}
@@ -33,16 +36,26 @@ diesel::table! {
members (id) {
id -> Int4,
family_id -> Int4,
#[max_length = 30]
first_name -> Nullable<Varchar>,
#[max_length = 30]
last_name -> Nullable<Varchar>,
#[max_length = 30]
birth_last_name -> Nullable<Varchar>,
photo_id -> Nullable<Int4>,
#[max_length = 255]
email -> Nullable<Varchar>,
#[max_length = 30]
phone -> Nullable<Varchar>,
#[max_length = 155]
address -> Nullable<Varchar>,
#[max_length = 150]
city -> Nullable<Varchar>,
#[max_length = 12]
postal_code -> Nullable<Varchar>,
#[max_length = 2]
country -> Nullable<Varchar>,
#[max_length = 1]
sex -> Nullable<Varchar>,
time_create -> Int8,
time_update -> Int8,
@@ -71,11 +84,15 @@ diesel::table! {
diesel::table! {
photos (id) {
id -> Int4,
#[max_length = 36]
file_id -> Varchar,
time_create -> Int8,
#[max_length = 150]
mime_type -> Varchar,
#[max_length = 130]
sha512 -> Varchar,
file_size -> Int4,
#[max_length = 130]
thumb_sha512 -> Varchar,
}
}
@@ -83,12 +100,16 @@ diesel::table! {
diesel::table! {
users (id) {
id -> Int4,
#[max_length = 30]
name -> Varchar,
#[max_length = 255]
email -> Varchar,
password -> Nullable<Varchar>,
time_create -> Int8,
#[max_length = 150]
reset_password_token -> Nullable<Varchar>,
time_gen_reset_token -> Int8,
#[max_length = 150]
delete_account_token -> Nullable<Varchar>,
time_gen_delete_account_token -> Int8,
time_activate -> Int8,