Skip to content
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
4 changes: 2 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const isLocalhost = window.location.hostname === 'localhost' ||
window.location.hostname.includes('192.168');

const baseURL = isLocalhost
? 'http://127.0.0.1:8000/'
: 'http://187.33.149.121:8000/';
? 'http://127.0.0.1:8000/api/'
: '/api/';

const token = isLocalhost
? '5fc8db25bf14ab3c73c9ba1aee9c24041417eb1a'
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ChatbotEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ChatbotEditor = () => {
if (id) {
const fetchBot = async () => {
try {
const response = await api.get(`/api/botflows/${id}/`);
const response = await api.get(`botflows/${id}/`);
setName(response.data.name);
setDescription(response.data.description);
} catch (error) {
Expand All @@ -33,9 +33,9 @@ const ChatbotEditor = () => {

try {
if (id) {
await api.put(`/api/botflows/${id}/`, { name, description, phone_number: '000000000' });
await api.put(`botflows/${id}/`, { name, description, phone_number: '000000000' });
} else {
const response = await api.post(`/api/botflows/`, { name, description, phone_number: '000000000' });
const response = await api.post(`botflows/`, { name, description, phone_number: '000000000' });
return navigate(`/chatbot/${response.data.id}`);
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Dashboard() {
const confirmDelete = async () => {
if (botToDelete) {
try {
await api.delete(`/api/botflows/${botToDelete.id}/`);
await api.delete(`botflows/${botToDelete.id}/`);
setChatbots((prev) => prev.filter((b) => b.id !== botToDelete.id));
} catch (err) {
console.error('Error esborrant el bot:', err);
Expand All @@ -41,7 +41,7 @@ function Dashboard() {
useEffect(() => {
const fetchBotflows = async () => {
try {
const response = await api.get<Botflow[]>(`/api/botflows/`);
const response = await api.get<Botflow[]>(`botflows/`);
setChatbots(response.data);
} catch (error) {
console.error('Error fetching botflows:', error);
Expand Down
24 changes: 12 additions & 12 deletions src/services/flowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ export const flowService = {
}

try {
const existingResponse = await api.get(`/api/botflows/${botflowId}/nodes/`);
const existingResponse = await api.get(`botflows/${botflowId}/nodes/`);
const existingNodes = existingResponse.data || [];

for (const node of existingNodes) {
if (node.next_node) {
await api.put(`/api/nodes/${node.id}/`, {
await api.put(`nodes/${node.id}/`, {
...node,
next_node: null
});
}
}

try {
const listOptionsResponse = await api.get('/api/list-options/');
const listOptionsResponse = await api.get('list-options/');
const listOptions = listOptionsResponse.data || [];

const relevantOptions = listOptions.filter((option: any) => {
Expand All @@ -90,14 +90,14 @@ export const flowService = {
});

for (const option of relevantOptions) {
await api.delete(`/api/list-options/${option.id}/`);
await api.delete(`list-options/${option.id}/`);
}
} catch (listError) {
console.warn("Error cleaning list options:", listError);
}

for (const node of existingNodes) {
await api.delete(`/api/nodes/${node.id}/`);
await api.delete(`nodes/${node.id}/`);
}
} catch (e) {
console.warn("Error al limpiar nodos:", e);
Expand Down Expand Up @@ -129,7 +129,7 @@ export const flowService = {
try {
for (let i = 1; i <= nodesData.length; i++) {
try {
await api.delete(`/api/nodes/${i}/`);
await api.delete(`nodes/${i}/`);
} catch (error) {
// Ignore errors - node might not exist
}
Expand All @@ -140,7 +140,7 @@ export const flowService = {

for (const nodeData of nodesData) {
try {
await api.post(`/api/nodes/`, nodeData);
await api.post(`nodes/`, nodeData);
} catch (nodeError: unknown) {
const isAxiosError = (error: any): error is { response?: { data?: any; status?: number } } => {
return error && typeof error === 'object' && 'response' in error;
Expand All @@ -153,7 +153,7 @@ export const flowService = {

if (nodeError.response?.status === 400) {
try {
await api.put(`/api/nodes/${nodeData.id}/`, nodeData);
await api.put(`nodes/${nodeData.id}/`, nodeData);
} catch (putError) {
console.error(`PUT also failed for node ${nodeData.id}:`, putError);
}
Expand All @@ -165,7 +165,7 @@ export const flowService = {
}

try {
const allNodesResponse = await api.get(`/api/botflows/${botflowId}/nodes/`);
const allNodesResponse = await api.get(`botflows/${botflowId}/nodes/`);
const allNodes = allNodesResponse.data;

const nodesByPosition = new Map();
Expand Down Expand Up @@ -206,7 +206,7 @@ export const flowService = {
}

try {
await api.put(`/api/nodes/${backendSourceNode.id}/`, {
await api.put(`nodes/${backendSourceNode.id}/`, {
...backendSourceNode,
next_node: backendTargetNode.id
});
Expand Down Expand Up @@ -259,7 +259,7 @@ export const flowService = {
}

try {
await api.post('/api/list-options/', {
await api.post('list-options/', {
node: backendNodeId,
label: option,
target_node: backendTargetNode.id
Expand All @@ -286,7 +286,7 @@ export const flowService = {

loadFlowNodes: async (botflowId: number) => {
try {
const response = await api.get(`/api/botflows/${botflowId}/nodes/`);
const response = await api.get(`botflows/${botflowId}/nodes/`);
return response.data;
} catch (error) {
console.error("Error cargando nodos:", error);
Expand Down