Can toggle accommodations module
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Pierre HUBERT 2024-05-23 19:28:29 +02:00
parent 32d3793025
commit 2f1df6c117
9 changed files with 49 additions and 3 deletions

View File

@ -88,10 +88,12 @@ export class Family implements FamilyAPI {
export class ExtendedFamilyInfo extends Family {
public disable_couple_photos: boolean;
public enable_genealogy: boolean;
public enable_accommodations: boolean;
constructor(p: any) {
super(p);
this.disable_couple_photos = p.disable_couple_photos;
this.enable_genealogy = p.enable_genealogy;
this.enable_accommodations = p.enable_accommodations;
}
}
@ -235,6 +237,7 @@ export class FamilyApi {
id: number;
name?: string;
enable_genealogy?: boolean;
enable_accommodations?: boolean;
disable_couple_photos?: boolean;
}): Promise<void> {
await APIClient.exec({
@ -243,6 +246,7 @@ export class FamilyApi {
jsonData: {
name: settings.name,
enable_genealogy: settings.enable_genealogy,
enable_accommodations: settings.enable_accommodations,
disable_couple_photos: settings.disable_couple_photos,
},
});

View File

@ -71,6 +71,9 @@ function FamilySettingsCard(): React.ReactElement {
const [enableGenealogy, setEnableGenealogy] = React.useState(
family.family.enable_genealogy
);
const [enableAccommodations, setEnableAccommodations] = React.useState(
family.family.enable_accommodations
);
const canEdit = family.family.is_admin;
@ -86,6 +89,7 @@ function FamilySettingsCard(): React.ReactElement {
id: family.family.family_id,
name: newName,
enable_genealogy: enableGenealogy,
enable_accommodations: enableAccommodations,
});
family.reloadFamilyInfo();
@ -118,14 +122,12 @@ function FamilySettingsCard(): React.ReactElement {
label="Identifiant"
value={family.family.family_id}
/>
<TextField
disabled
fullWidth
label="Création de la famille"
value={formatDate(family.family.time_create)}
/>
<TextField
fullWidth
label="Nom de la famille"
@ -136,7 +138,6 @@ function FamilySettingsCard(): React.ReactElement {
maxLength: ServerApi.Config.constraints.family_name_len.max,
}}
/>
<FormControlLabel
disabled={!canEdit}
control={
@ -147,6 +148,16 @@ function FamilySettingsCard(): React.ReactElement {
}
label="Activer le module de généalogie"
/>
<FormControlLabel
disabled={!canEdit}
control={
<Switch
checked={enableAccommodations}
onChange={(_e, c) => setEnableAccommodations(c)}
/>
}
label="Activer le module de réservation de logements"
/>
</Box>
</CardContent>
<CardActions>

View File

@ -1,2 +1,5 @@
ALTER TABLE public.families
DROP COLUMN enable_accommodations;
DROP TABLE IF EXISTS accomodations_reservations;
DROP TABLE IF EXISTS accomodations_list;

View File

@ -1,3 +1,10 @@
-- Add column to toggle accommodations module
ALTER TABLE public.families
ADD enable_accommodations boolean NOT NULL DEFAULT false;
COMMENT
ON COLUMN public.families.enable_accommodations IS 'Specify whether accommodations feature is enabled for the family';
-- Create tables
CREATE TABLE IF NOT EXISTS accommodations_list
(

View File

@ -80,6 +80,7 @@ struct RichFamilyInfo {
#[serde(flatten)]
membership: FamilyMembership,
enable_genealogy: bool,
enable_accommodations: bool,
disable_couple_photos: bool,
}
@ -90,6 +91,7 @@ pub async fn single_info(f: FamilyInPath) -> HttpResult {
Ok(HttpResponse::Ok().json(RichFamilyInfo {
membership,
enable_genealogy: family.enable_genealogy,
enable_accommodations: family.enable_accommodations,
disable_couple_photos: family.disable_couple_photos,
}))
}
@ -105,6 +107,7 @@ pub async fn leave(f: FamilyInPath) -> HttpResult {
pub struct UpdateFamilyBody {
name: Option<String>,
enable_genealogy: Option<bool>,
enable_accommodations: Option<bool>,
disable_couple_photos: Option<bool>,
}
@ -127,6 +130,10 @@ pub async fn update(
family.enable_genealogy = enable_genealogy;
}
if let Some(enable_accommodations) = req.enable_accommodations {
family.enable_accommodations = enable_accommodations;
}
if let Some(disable_couple_photos) = req.disable_couple_photos {
family.disable_couple_photos = disable_couple_photos;
}

View File

@ -204,6 +204,17 @@ async fn main() -> std::io::Result<()> {
"/family/{id}/genealogy/data/import",
web::put().to(data_controller::import_family),
)
// [ACCOMODATIONS] List controller
// TODO : create
// TODO : update
// TODO : delete
// TODO : list
// [ACCOMODATIONS] Reservations controller
// TODO : create
// TODO : update
// TODO : delete
// TODO : list
// TODO : validate or reject
// Photos controller
.route(
"/photo/{id}",

View File

@ -66,6 +66,7 @@ pub struct Family {
pub invitation_code: String,
pub disable_couple_photos: bool,
pub enable_genealogy: bool,
pub enable_accommodations: bool,
}
impl Family {

View File

@ -56,6 +56,7 @@ diesel::table! {
invitation_code -> Varchar,
disable_couple_photos -> Bool,
enable_genealogy -> Bool,
enable_accommodations -> Bool,
}
}

View File

@ -175,6 +175,7 @@ pub async fn update_family(family: &Family) -> anyhow::Result<()> {
families::dsl::name.eq(family.name.clone()),
families::dsl::invitation_code.eq(family.invitation_code.clone()),
families::dsl::enable_genealogy.eq(family.enable_genealogy),
families::dsl::enable_accommodations.eq(family.enable_accommodations),
families::dsl::disable_couple_photos.eq(family.disable_couple_photos),
))
.execute(conn)