feat: Import Presets from NewConversationMenu

feat(FileUpload.jsx): add support for importing JSON files and fetching presets after import
feat(NewConversationMenu.jsx): add FileUpload component to select and import JSON files
feat(fetchers.js): add handleFileSelected function to handle importing JSON files and uploading presets to the server
This commit is contained in:
Daniel Avila 2023-04-04 23:18:58 -04:00
parent 0846aa0436
commit 5aa6b516ed
3 changed files with 77 additions and 1 deletions

View file

@ -72,3 +72,23 @@ export function useManualSWR({ path, params, type, onSuccess }) {
const fetchFunction = type === 'get' ? _.partialRight(axiosFetcher, params) : postRequest;
return useSWRMutation(path, fetchFunction, options);
}
export const handleFileSelected = async (jsonData, callback) => {
try {
const response = await fetch('/api/presets', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(jsonData),
});
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
}
callback();
} catch (error) {
console.error('Error uploading the preset:', error);
}
};