feat: add form and page platform
This commit is contained in:
@@ -14,19 +14,38 @@ import type {
|
||||
ReferenceListFilters,
|
||||
} from "../application/reference-feature-api.js";
|
||||
|
||||
function useReferenceFeatureInput(): ReferenceFeatureInput {
|
||||
export function useReferenceFeatureInput(): ReferenceFeatureInput {
|
||||
const candidate = useApplication().features.get(REFERENCE_FEATURE_ID);
|
||||
if (
|
||||
!candidate ||
|
||||
typeof candidate !== "object" ||
|
||||
typeof (candidate as ReferenceFeatureInput).listResources !== "function" ||
|
||||
typeof (candidate as ReferenceFeatureInput).createResource !== "function"
|
||||
typeof (candidate as ReferenceFeatureInput).createResource !== "function" ||
|
||||
typeof (candidate as ReferenceFeatureInput).getResource !== "function"
|
||||
) {
|
||||
throw new Error("Reference feature application input is invalid");
|
||||
}
|
||||
return candidate as ReferenceFeatureInput;
|
||||
}
|
||||
|
||||
export function useReferenceDetail(resourceId: string) {
|
||||
const input = useReferenceFeatureInput();
|
||||
const query = useApplicationQuery({
|
||||
queryKey: referenceQueryKeys.detail(resourceId),
|
||||
execute: ({ signal }) => input.getResource(resourceId, { signal }),
|
||||
});
|
||||
return Object.freeze({ query });
|
||||
}
|
||||
|
||||
export function useReferenceCreate() {
|
||||
const input = useReferenceFeatureInput();
|
||||
return useApplicationMutation({
|
||||
execute: input.createResource,
|
||||
invalidate: [referenceQueryKeys.all()],
|
||||
currentData: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function useReferenceFeature() {
|
||||
const input = useReferenceFeatureInput();
|
||||
const routeInput = useRouteInput();
|
||||
|
||||
Reference in New Issue
Block a user