mirror of
https://github.com/strapi/strapi.git
synced 2025-10-06 13:52:13 +00:00
fix: useDoc returns document id for single types
Co-authored-by: Bassel Kanso <basselkanso82@gmail.com> Co-authored-by: Jamie Howard <jhoward1994@users.noreply.github.com>
This commit is contained in:
parent
6819dcbd7c
commit
351e3e4a8d
@ -195,16 +195,23 @@ const useDoc = () => {
|
|||||||
throw new Error('Could not find model in url params');
|
throw new Error('Could not find model in url params');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const document = useDocument(
|
||||||
collectionType,
|
|
||||||
model: slug,
|
|
||||||
id: origin || id === 'create' ? undefined : id,
|
|
||||||
...useDocument(
|
|
||||||
{ documentId: origin || id, model: slug, collectionType, params },
|
{ documentId: origin || id, model: slug, collectionType, params },
|
||||||
{
|
{
|
||||||
skip: id === 'create' || (!origin && !id && collectionType !== SINGLE_TYPES),
|
skip: id === 'create' || (!origin && !id && collectionType !== SINGLE_TYPES),
|
||||||
}
|
}
|
||||||
),
|
);
|
||||||
|
|
||||||
|
const singleTypeId = collectionType === SINGLE_TYPES ? document.document?.documentId : undefined;
|
||||||
|
|
||||||
|
const returnId = origin || id === 'create' ? undefined : id || singleTypeId;
|
||||||
|
|
||||||
|
// console.log('return id', returnId);
|
||||||
|
return {
|
||||||
|
collectionType,
|
||||||
|
model: slug,
|
||||||
|
id: returnId,
|
||||||
|
...document,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user