From f73877843dce4946ace9ec1fada9fc9dc71d8b8e Mon Sep 17 00:00:00 2001 From: Sheng Tao Date: Sun, 21 May 2023 18:27:46 +0200 Subject: [PATCH] fixed duration not showing correctly in the edit building page --- frontend/lib/building.ts | 4 ++++ frontend/pages/admin/data/buildings/edit.tsx | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/lib/building.ts b/frontend/lib/building.ts index 5405f982..3aba3634 100644 --- a/frontend/lib/building.ts +++ b/frontend/lib/building.ts @@ -157,6 +157,10 @@ export function getDurationFromMinutes(durationInMinutes: number) { .padStart(2, "0")}` } +export function durationToMinutes(duration: string): number { + const [hours, minutes, seconds] = duration.split(':').map(Number); + return hours * 60 + minutes; +} export const getNewPublicId = async () => { const request_url: string = `${process.env.NEXT_PUBLIC_BASE_API_URL}${process.env.NEXT_PUBLIC_API_GET_NEW_PUBLIC_ID_BUILDING}`; diff --git a/frontend/pages/admin/data/buildings/edit.tsx b/frontend/pages/admin/data/buildings/edit.tsx index 21e69e0d..27feeb98 100644 --- a/frontend/pages/admin/data/buildings/edit.tsx +++ b/frontend/pages/admin/data/buildings/edit.tsx @@ -2,7 +2,7 @@ import React, {ChangeEvent, useEffect, useState} from "react"; import {useRouter} from "next/router"; import {Button, Col, Container, Form, Row} from "react-bootstrap"; import { - deleteBuildingComment, + deleteBuildingComment, durationToMinutes, getBuildingComment, getBuildingInfo, getDurationFromMinutes, @@ -35,7 +35,7 @@ function AdminDataBuildingsEdit() { const [regionId, setRegionId] = useState(-1); //used for collecting the right id to post/patch const [syndicId, setSyndicId] = useState(-1); //used for collecting the right id to post/patch const [manual, setManual] = useState(null); - const [duration, setDuration] = useState("00:00"); + // const [duration, setDuration] = useState("00:00"); const [publicId, setPublicId] = useState(""); const [validated, setValidated] = useState(false); const [durationInMinutes, setDurationInMinutes] = useState(0); @@ -124,7 +124,8 @@ function AdminDataBuildingsEdit() { setPostalCode(res.data.postal_code); setCity(res.data.city); setName(res.data.name ? res.data.name : ""); - setDuration(res.data.duration); + console.log(res.data.duration); + setDurationInMinutes(durationToMinutes(res.data.duration)); setPublicId(res.data.public_id ?? ""); const region = await getRegion(res.data.region); setRegionId(region.data.id);