diff --git a/src_generic/components/ProfileView.tsx b/src_generic/components/ProfileView.tsx
index 0134d0e..0e42f6f 100644
--- a/src_generic/components/ProfileView.tsx
+++ b/src_generic/components/ProfileView.tsx
@@ -10,18 +10,43 @@ export default function ProfileView() {
const resourceConfig = appConfig?.resources.find(r => r.name === profileConfig?.resource);
if (!profileConfig || !resourceConfig) {
- debugger;
return Profile configuration not found.;
}
- const { useMe, useUpdate } = useResource(resourceConfig);
+ // Create a modified config where only extraFields are editable
+ const editableConfig = React.useMemo(() => {
+ const newFields = { ...resourceConfig.fields };
+ const extraFields = profileConfig.extraFields || [];
+
+ Object.keys(newFields).forEach(key => {
+ newFields[key] = {
+ ...newFields[key],
+ readOnly: !extraFields.includes(key),
+ };
+ });
+
+ return {
+ ...resourceConfig,
+ fields: newFields,
+ };
+ }, [resourceConfig, profileConfig.extraFields]);
+
+ const { useMe, useUpdateMe } = useResource(resourceConfig);
const { data: profile, isLoading, error } = useMe();
- const updateMutation = useUpdate();
+ const updateMutation = useUpdateMe();
const handleSave = async (formData: any) => {
try {
- const id = profile[resourceConfig.primaryKey];
- await updateMutation.mutateAsync({ id, data: formData });
+ // Only send editable fields to prevent accidental overwrites of read-only data
+ const extraFields = profileConfig.extraFields || [];
+ const dataToSave = Object.keys(formData)
+ .filter(key => extraFields.includes(key))
+ .reduce((obj: any, key) => {
+ obj[key] = formData[key];
+ return obj;
+ }, {});
+
+ await updateMutation.mutateAsync(dataToSave);
} catch (err) {
console.error('Profile update failed:', err);
}
@@ -46,7 +71,7 @@ export default function ProfileView() {
window.history.back()}
diff --git a/src_generic/configuration.ts b/src_generic/configuration.ts
index f436f12..4989f6f 100644
--- a/src_generic/configuration.ts
+++ b/src_generic/configuration.ts
@@ -43,5 +43,7 @@ export const configuration: Record = {
export const profileConfiguration = {
"extraFields": ['name'],
- "resource": "payors"
+ "resource": "payors",
+ // not in use
+ "hidden": true,
};
diff --git a/src_generic/hooks/useResource.ts b/src_generic/hooks/useResource.ts
index b722ac5..1c7a10a 100644
--- a/src_generic/hooks/useResource.ts
+++ b/src_generic/hooks/useResource.ts
@@ -92,12 +92,27 @@ export function useResource(config: ResourceConfig) {
},
});
+ // --- UPDATE ME ---
+ const useUpdateMe = () =>
+ useMutation({
+ mutationFn: async (data: Partial) => {
+ // @ts-ignore
+ const res = await api.put(`${endpoint}/me`, data);
+ return res.data;
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: [name, "me"] });
+ queryClient.invalidateQueries({ queryKey: [name, "list"] });
+ },
+ });
+
return {
useList,
useRead,
useMe,
useCreate,
useUpdate,
+ useUpdateMe,
useDelete,
getListQueryOptions,
};