0.3.1.3
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user