(ui) edit teams

This commit is contained in:
Ishaan Jaff 2024-03-29 20:20:04 -07:00
parent 4a6aa3ee61
commit f62b3f5d2c
2 changed files with 73 additions and 19 deletions

View file

@ -817,6 +817,42 @@ export const teamCreateCall = async (
}
};
export const teamUpdateCall = async (
accessToken: string,
formValues: Record<string, any> // Assuming formValues is an object
) => {
try {
console.log("Form Values in teamUpateCall:", formValues); // Log the form values before making the API call
const url = proxyBaseUrl ? `${proxyBaseUrl}/team/update` : `/team/update`;
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
...formValues, // Include formValues in the request body
}),
});
if (!response.ok) {
const errorData = await response.text();
message.error("Failed to update team: " + errorData);
console.error("Error response from the server:", errorData);
throw new Error("Network response was not ok");
}
const data = await response.json();
console.log("Update Team Response:", data);
return data;
// Handle success - you might want to update some state or UI based on the created key
} catch (error) {
console.error("Failed to create key:", error);
throw error;
}
};
export interface Member {
role: string;
user_id: string | null;

View file

@ -1,7 +1,7 @@
import React, { useState, useEffect } from "react";
import Link from "next/link";
import { Typography } from "antd";
import { teamDeleteCall } from "./networking";
import { teamDeleteCall, teamUpdateCall } from "./networking";
import { InformationCircleIcon, PencilAltIcon, PencilIcon, StatusOnlineIcon, TrashIcon } from "@heroicons/react/outline";
import {
Button as Button2,
@ -71,7 +71,8 @@ const EditTeamModal = ({ visible, onCancel, team, onSubmit }) => {
form
.validateFields()
.then((values) => {
onSubmit(team.team_id, values);
const updatedValues = {...values, team_id: team.team_id};
onSubmit(updatedValues);
form.resetFields();
})
.catch((error) => {
@ -90,6 +91,7 @@ const EditTeamModal = ({ visible, onCancel, team, onSubmit }) => {
>
<Form
form={form}
onFinish={handleEditSubmit}
initialValues={team} // Pass initial values here
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}
@ -150,11 +152,27 @@ const EditTeamModal = ({ visible, onCancel, team, onSubmit }) => {
setSelectedTeam(null);
};
const handleEditSubmit = (teamId: string, values) => {
const handleEditSubmit = async (formValues: Record<string, any>) => {
// Call API to update team with teamId and values
// Handle success or failure accordingly
console.log("Editing team:", teamId, "with values:", values);
const teamId = formValues.team_id; // get team_id
console.log("handleEditSubmit:", formValues);
if (accessToken == null) {
return;
}
// Update the teams state with the updated team data
if (teams) {
const updatedTeams = teams.map((team) =>
team.team_id === teamId ? formValues : team
);
setTeams(updatedTeams);
}
console.log("Editing team:", teamId, "with values:", formValues);
message.success("Team updated successfully");
teamUpdateCall(accessToken, formValues);
setEditModalVisible(false);
setSelectedTeam(null);
};