Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
fixed duration not showing correctly in the edit building page
Browse files Browse the repository at this point in the history
  • Loading branch information
GashinRS committed May 21, 2023
1 parent dfc36e3 commit f738778
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions frontend/lib/building.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
7 changes: 4 additions & 3 deletions frontend/pages/admin/data/buildings/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -35,7 +35,7 @@ function AdminDataBuildingsEdit() {
const [regionId, setRegionId] = useState<number>(-1); //used for collecting the right id to post/patch
const [syndicId, setSyndicId] = useState<number>(-1); //used for collecting the right id to post/patch
const [manual, setManual] = useState<File | null>(null);
const [duration, setDuration] = useState<string>("00:00");
// const [duration, setDuration] = useState<string>("00:00");
const [publicId, setPublicId] = useState<string>("");
const [validated, setValidated] = useState<boolean>(false);
const [durationInMinutes, setDurationInMinutes] = useState<number>(0);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f738778

Please sign in to comment.