Moves editing into forms. Every doc has a page now. BUG: state not refreshed after mutation
This commit is contained in:
46
src/components/documents/location/LocationEditForm.tsx
Normal file
46
src/components/documents/location/LocationEditForm.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { AutoSaveTextarea } from "@/components/AutoSaveTextarea";
|
||||
import { pb } from "@/lib/pocketbase";
|
||||
import type { Location } from "@/lib/types";
|
||||
|
||||
/**
|
||||
* Renders an editable location form
|
||||
*/
|
||||
export const LocationEditForm = ({ location }: { location: Location }) => {
|
||||
async function saveLocationName(name: string) {
|
||||
await pb.collection("documents").update(location.id, {
|
||||
data: {
|
||||
...location.data,
|
||||
location: {
|
||||
...location.data.location,
|
||||
name,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function saveLocationDescription(description: string) {
|
||||
await pb.collection("documents").update(location.id, {
|
||||
data: {
|
||||
...location.data,
|
||||
location: {
|
||||
...location.data.location,
|
||||
description,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
<AutoSaveTextarea
|
||||
multiline={false}
|
||||
value={location.data.location.name}
|
||||
onSave={saveLocationName}
|
||||
/>
|
||||
<AutoSaveTextarea
|
||||
value={location.data.location.description}
|
||||
onSave={saveLocationDescription}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user