Skip to content
Draft
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: 4 additions & 0 deletions packages/webapp/src/apiConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export const marketDirectoryPartnersUrl = `${URI}/market_directory_partners`;
export const supportTicketUrl = `${URI}/support_ticket`;
export const offlineEventLogUrl = `${URI}/offline_event_log`;
export const tapeSurveyUrl = `${URI}/tape_survey`;
export const farmNoteUrl = `${URI}/farm_note`;
export const farmNotesReadUrl = `${URI}/farm_notes_read`;

export const url = URI;

Expand Down Expand Up @@ -163,5 +165,7 @@ export default {
weatherUrl,
marketDirectoryInfoUrl,
marketDirectoryPartnersUrl,
farmNoteUrl,
farmNotesReadUrl,
url,
};
2 changes: 1 addition & 1 deletion packages/webapp/src/store/api/apiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import { API_TAGS, ApiTag } from './apiTags';
*/
export const invalidateTags = (tags: ApiTag[]) => api.util.invalidateTags(tags);

const NON_JSON_ENDPOINT_KEYS = new Set(['addSupportTicket']);
const NON_JSON_ENDPOINT_KEYS = new Set(['addSupportTicket', 'addFarmNote', 'editFarmNote']);

export const api = createApi({
baseQuery: fetchBaseQuery({
Expand Down
2 changes: 2 additions & 0 deletions packages/webapp/src/store/api/apiTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const FarmTags = [
'Weather',
'MarketDirectoryInfo',
'TapeSurvey',
'FarmNote',
'FarmNotesRead',
] as const;

/**
Expand Down
95 changes: 95 additions & 0 deletions packages/webapp/src/store/api/farmNoteApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2026 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

import { api } from './apiSlice';
import { farmNoteUrl } from '../../apiConfig';
import { FarmNote } from './types';

type FarmNoteData = {
note: string;
is_private: boolean;
};

interface AddFarmNoteReqBody {
file?: File;
data: FarmNoteData;
}

interface EditFarmNoteReqBody {
id: string;
file?: File;
data: FarmNoteData & {
image_url?: null;
};
}

export const farmNoteApi = api.injectEndpoints({
endpoints: (build) => ({
getFarmNotes: build.query<FarmNote[], void>({
query: () => ({
url: farmNoteUrl,
method: 'GET',
}),
providesTags: ['FarmNote'],
}),
addFarmNote: build.mutation<FarmNote, AddFarmNoteReqBody>({
query: ({ file, data }) => {
// Mirrors supportTicketApi.ts
// Must similarly add to non-JSON endpoint keys in apiSlice.ts
const formData = new FormData();
if (file) {
formData.append('_file_', file);
}
formData.append('data', JSON.stringify(data));
return {
url: farmNoteUrl,
method: 'POST',
body: formData,
};
},
invalidatesTags: ['FarmNote'],
}),
editFarmNote: build.mutation<FarmNote, EditFarmNoteReqBody>({
query: ({ id, file, data }) => {
const formData = new FormData();
if (file) {
formData.append('_file_', file);
}
formData.append('data', JSON.stringify(data));

return {
url: `${farmNoteUrl}/${id}`,
method: 'PATCH',
body: formData,
};
},
invalidatesTags: ['FarmNote'],
}),
deleteFarmNote: build.mutation<void, string>({
query: (id) => ({
url: `${farmNoteUrl}/${id}`,
method: 'DELETE',
}),
invalidatesTags: ['FarmNote'],
}),
}),
});

export const {
useGetFarmNotesQuery,
useAddFarmNoteMutation,
useEditFarmNoteMutation,
useDeleteFarmNoteMutation,
} = farmNoteApi;
38 changes: 38 additions & 0 deletions packages/webapp/src/store/api/farmNotesReadApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2026 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

import { api } from './apiSlice';
import { farmNotesReadUrl } from '../../apiConfig';
import { FarmNotesRead } from './types';

export const farmNotesReadApi = api.injectEndpoints({
endpoints: (build) => ({
getFarmNotesRead: build.query<FarmNotesRead, void>({
query: () => ({
url: farmNotesReadUrl,
method: 'GET',
}),
providesTags: ['FarmNotesRead'],
}),
markFarmNotesRead: build.mutation<void, void>({
query: () => ({
url: farmNotesReadUrl,
method: 'PATCH',
}),
}),
}),
});

export const { useGetFarmNotesReadQuery, useMarkFarmNotesReadMutation } = farmNotesReadApi;
15 changes: 15 additions & 0 deletions packages/webapp/src/store/api/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,18 @@ export interface SupportTicketData {
attachments: {};
};
}

export interface FarmNote {
id: string;
farm_id: string;
user_id: string;
note: string;
is_private: boolean;
image_url?: string | null;
created_at: string;
to_sync?: boolean; // client-only flag for offline-queued notes
}

export interface FarmNotesRead {
last_read_at: string | null;
}
Loading