Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emergency flow page #45

Merged
merged 8 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ export async function createEmergency(
emergency: CreateEmergencyRequest,
): Promise<APIResult<Emergency>> {
try {
const response = await post("/api/emergencies", emergency);
if (!process.env.API_URL) {
throw new Error("API URL is not defined");
}

const url = `${process.env.API_URL}/emergencyFlow`;

const response = await post(url, emergency);
const json = (await response.json()) as Emergency;
return { success: true, data: json };
} catch (error) {
Expand All @@ -75,7 +81,13 @@ export async function createEmergency(

export async function getEmergency(id: string): Promise<APIResult<Emergency>> {
try {
const response = await get(`/api/emergencies/${id}`);
if (!process.env.API_URL) {
throw new Error("API URL is not defined");
}

const url = `${process.env.API_URL}/emergencyFlow/${id}`;

const response = await get(url);
const json = (await response.json()) as Emergency;
return { success: true, data: json };
} catch (error) {
Expand All @@ -85,7 +97,12 @@ export async function getEmergency(id: string): Promise<APIResult<Emergency>> {

export async function getAllEmergencies(): Promise<APIResult<Emergency[]>> {
try {
const response = await get(`/api/emergencies/`);
if (!process.env.API_URL) {
throw new Error("API URL is not defined");
}

const url = `${process.env.API_URL}/emergencyFlow`;
const response = await get(url);
const json = (await response.json()) as Emergency[];
// const parsedJson = json.map((element) => (element));
return { success: true, data: json };
Expand All @@ -99,8 +116,12 @@ export async function updateEmergency(
emergency: UpdateEmergencyRequest,
): Promise<APIResult<Emergency>> {
try {
// your code here
const response = await put(`/api/emergencies/${emergency._id}`, emergency);
if (!process.env.API_URL) {
throw new Error("API URL is not defined");
}

const url = `${process.env.API_URL}/emergencyFlow/${emergency._id}`;
const response = await put(url, emergency);
const json = (await response.json()) as Emergency;
return { success: true, data: json };
} catch (error) {
Expand Down
14 changes: 11 additions & 3 deletions admin-portal-frontend/src/app/pages/EmergencyFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { useRouter } from "next/navigation";
import React from "react";

import { CreateEmergencyRequest, createEmergency } from "../../../emergencies";
import { CreateEmergencyRequest, createEmergency } from "../api/emergencies";

import styles from "./EmergencyFlowStyles";

Expand Down Expand Up @@ -130,8 +130,16 @@ const EmergencyFlow: React.FC = () => {
// If the problem is something we don't really control, such as network
// issues or an unexpected exception on the server side, then use a
// banner, modal, popup, or similar.

alert(result.error);
if (
!emergencyTitle ||
emergencyTitle === "" ||
!emergencySubtitle ||
emergencyTitle === ""
) {
alert("Missing required title or subtitle fields. Please resubmit the form.");
} else {
alert(result.error);
}
console.log(result);
}
})
Expand Down
5 changes: 0 additions & 5 deletions package.json

This file was deleted.

Loading