Skip to content

Commit 97b4da6

Browse files
committed
refactor: rename statements to entries
1 parent d054441 commit 97b4da6

23 files changed

+378
-514
lines changed

src/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use client';
22

33
import React from 'react';
4-
import { StatementsProvider } from './context/StatementsProvider';
4+
import { EntriesProvider } from './context/EntriesProvider';
55
import LoginPage from './components/LoginPage';
66
import Header from './components/Header';
77
import MainPage from './components/MainPage';
88
import { TooltipProvider } from '@radix-ui/react-tooltip';
9-
import { useStatements } from './hooks/useStatements';
9+
import { useEntries } from './hooks/useEntries';
1010
import { QuestionsProvider } from './context/QuestionsProvider';
1111

1212
// Outer Component: Responsible only for setting up the environment (the providers) for the rest of the app.
1313
const AppContent: React.FC = () => {
14-
const { data, setData } = useStatements();
14+
const { data, setData } = useEntries();
1515

1616
const handleLoginSubmit = (username: string, managerEmail: string) => {
1717
// Dispatch an action to update the username in context.
@@ -36,11 +36,11 @@ const AppContent: React.FC = () => {
3636
const App: React.FC = () => {
3737
return (
3838
<TooltipProvider>
39-
<StatementsProvider>
39+
<EntriesProvider>
4040
<QuestionsProvider>
4141
<AppContent />
4242
</QuestionsProvider>
43-
</StatementsProvider>
43+
</EntriesProvider>
4444
</TooltipProvider>
4545
);
4646
};

src/api/entriesApi.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { Entry } from '../../types/entries';
2+
3+
const API_URL = import.meta.env.VITE_API_URL;
4+
console.log('Backend API:', API_URL);
5+
6+
export async function postNewEntry(entry: Entry): Promise<void> {
7+
try {
8+
const response = await fetch(`${API_URL}/newEntry`, {
9+
method: 'POST',
10+
headers: {
11+
'Content-Type': 'application/json',
12+
},
13+
body: JSON.stringify(entry),
14+
});
15+
if (!response.ok) {
16+
throw new Error(`HTTP error on POST! status: ${response.status}`);
17+
}
18+
const data = await response.json();
19+
console.log('Successfully posted entry:', data);
20+
// Optionally fetch updated data if needed...
21+
} catch (error) {
22+
console.error('Error posting new entry:', error);
23+
}
24+
}
25+
26+
export async function updateEntry(entry: Entry): Promise<void> {
27+
try {
28+
const response = await fetch(`${API_URL}/updateEntry`, {
29+
method: 'PUT', // or PATCH, depending on your backend implementation
30+
headers: {
31+
'Content-Type': 'application/json',
32+
},
33+
body: JSON.stringify(entry),
34+
});
35+
if (!response.ok) {
36+
throw new Error(`HTTP error on update! status: ${response.status}`);
37+
}
38+
const data = await response.json();
39+
console.log('Successfully updated entry:', data);
40+
} catch (error) {
41+
console.error('Error updating entry:', error);
42+
}
43+
}

src/api/statementsApi.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/components/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react';
2-
import { useStatements } from '../hooks/useStatements';
2+
import { useEntries } from '../hooks/useEntries';
33

44
import {
55
Dialog,
@@ -19,7 +19,7 @@ import LargeCircularQuestionCounter from './ui/questionCounter/LargeCircularQues
1919

2020
const Header: React.FC = () => {
2121
// const { questions, setQuestions } = useQuestions();
22-
const { data, setData } = useStatements();
22+
const { data, setData } = useEntries();
2323
const [isDashboardOpen, setIsDashboardOpen] = useState(false);
2424
const [isEditingEmail, setIsEditingEmail] = useState(false);
2525
const [managerEmailInput, setManagerEmailInput] = useState(

src/components/MainPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import React from 'react';
44
import StatementList from './statements/StatementList';
5-
import { useStatements } from '../hooks/useStatements';
5+
import { useEntries } from '../hooks/useEntries';
66

77
const MainPage: React.FC = () => {
8-
const { data } = useStatements();
8+
const { data } = useEntries();
99
const { username } = data;
1010
return (
1111
<main className='min-h-screen bg-gradient-to-b from-gray-50 to-gray-100 py-12 '>

0 commit comments

Comments
 (0)