This commit is contained in:
freedakgmail
2025-11-30 20:00:18 +08:00
parent 86e889cc2a
commit 0326894b09
6 changed files with 316 additions and 52 deletions
+7 -1
View File
@@ -224,10 +224,16 @@ function FamilyProviderInner({ children }: { children: React.ReactNode }) {
const updateMember = useCallback(async (id: string, updates: Partial<FamilyMember>) => {
if (!currentTree?.id) throw new Error('没有选择家族树')
// 将 undefined 转为 null,确保 JSON 序列化时能正确传递给后端
// 否则 JSON.stringify 会忽略 undefined 值,导致后端收不到更新
const payload = Object.fromEntries(
Object.entries(updates).map(([key, value]) => [key, value === undefined ? null : value])
)
const response = await fetch(`/api/trees/${currentTree.id}/members/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updates),
body: JSON.stringify(payload),
})
if (!response.ok) {