(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 { export interface Member {
role: string; role: string;
user_id: string | null; user_id: string | null;

View file

@ -1,7 +1,7 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import Link from "next/link"; import Link from "next/link";
import { Typography } from "antd"; import { Typography } from "antd";
import { teamDeleteCall } from "./networking"; import { teamDeleteCall, teamUpdateCall } from "./networking";
import { InformationCircleIcon, PencilAltIcon, PencilIcon, StatusOnlineIcon, TrashIcon } from "@heroicons/react/outline"; import { InformationCircleIcon, PencilAltIcon, PencilIcon, StatusOnlineIcon, TrashIcon } from "@heroicons/react/outline";
import { import {
Button as Button2, Button as Button2,
@ -71,13 +71,14 @@ const EditTeamModal = ({ visible, onCancel, team, onSubmit }) => {
form form
.validateFields() .validateFields()
.then((values) => { .then((values) => {
onSubmit(team.team_id, values); const updatedValues = {...values, team_id: team.team_id};
onSubmit(updatedValues);
form.resetFields(); form.resetFields();
}) })
.catch((error) => { .catch((error) => {
console.error("Validation failed:", error); console.error("Validation failed:", error);
}); });
}; };
return ( return (
<Modal <Modal
@ -90,6 +91,7 @@ const EditTeamModal = ({ visible, onCancel, team, onSubmit }) => {
> >
<Form <Form
form={form} form={form}
onFinish={handleEditSubmit}
initialValues={team} // Pass initial values here initialValues={team} // Pass initial values here
labelCol={{ span: 8 }} labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }} wrapperCol={{ span: 16 }}
@ -140,24 +142,40 @@ const EditTeamModal = ({ visible, onCancel, team, onSubmit }) => {
); );
}; };
const handleEditClick = (team: any) => { const handleEditClick = (team: any) => {
setSelectedTeam(team); setSelectedTeam(team);
setEditModalVisible(true); setEditModalVisible(true);
}; };
const handleEditCancel = () => { const handleEditCancel = () => {
setEditModalVisible(false); setEditModalVisible(false);
setSelectedTeam(null); setSelectedTeam(null);
}; };
const handleEditSubmit = (teamId: string, values) => { const handleEditSubmit = async (formValues: Record<string, any>) => {
// Call API to update team with teamId and values // Call API to update team with teamId and values
// Handle success or failure accordingly const teamId = formValues.team_id; // get team_id
console.log("Editing team:", teamId, "with values:", values);
message.success("Team updated successfully"); console.log("handleEditSubmit:", formValues);
setEditModalVisible(false); if (accessToken == null) {
setSelectedTeam(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);
};
const handleOk = () => { const handleOk = () => {
setIsTeamModalVisible(false); setIsTeamModalVisible(false);