Skip to content

Commit

Permalink
simplified code to rtk standard
Browse files Browse the repository at this point in the history
  • Loading branch information
Daan Janssen committed Aug 19, 2024
1 parent 1e9d3a3 commit d53c1bf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
2 changes: 1 addition & 1 deletion apps/ohsmart/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion packages/deposit/src/deposit/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
} from "@dans-framework/utils";
import type { Page } from "@dans-framework/pages";
import { useAuth } from "react-oidc-context";
import { useFetchSavedMetadataQuery } from "./depositApi";
import { useFetchSavedMetadataQuery } from "../features/submit/submitApi";
import {
useValidateAllKeysQuery,
getFormActions,
Expand Down
40 changes: 0 additions & 40 deletions packages/deposit/src/deposit/depositApi.ts

This file was deleted.

36 changes: 33 additions & 3 deletions packages/deposit/src/features/submit/submitApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import moment from "moment";
import { enqueueSnackbar } from "notistack";
import i18n from "../../languages/i18n";
import { formatFormData } from "./submitHelpers";
import type { SavedFormResponse } from "../../types/Metadata";

export const submitApi = createApi({
reducerPath: "submitApi",
baseQuery: fetchBaseQuery({
baseUrl: `${import.meta.env.VITE_PACKAGING_TARGET}/inbox/`,
baseUrl: `${import.meta.env.VITE_PACKAGING_TARGET}`,
}),
tagTypes: ["Forms"],
endpoints: (build) => ({
submitData: build.mutation({
query: ({ user, actionType, id, metadata, config, files }) => {
Expand Down Expand Up @@ -55,12 +57,13 @@ export const submitApi = createApi({
: `dataset/${actionType === "save" ? "DRAFT" : "PUBLISH"}`;

return ({
url: submitUrl,
url: `inbox/${submitUrl}`,
method: "POST",
headers: headers,
body: data,
})
},
invalidatesTags: (_res, _err, arg ) => [{ type: "Forms", id: arg.id }],
transformResponse: (response, _meta, arg) => {
store.dispatch(setMetadataSubmitStatus(
arg.actionType === "save" ? "saved" : "submitted",
Expand Down Expand Up @@ -89,7 +92,34 @@ export const submitApi = createApi({
});
},
}),
fetchSavedMetadata: build.query({
query: (id) => ({
url: `dataset/${id}`,
headers: { Accept: "application/json" },
}),
providesTags: (_res, _err, id) => [{ type: "Forms", id }],
transformResponse: (response: SavedFormResponse) => {
// mark previously submitted files
const modifiedResponse = {
...response,
md: {
...response.md,
"file-metadata":
response.md["file-metadata"] ?
response.md["file-metadata"].map((f) => ({
...f,
submittedFile: true,
}))
: [],
},
};
return modifiedResponse;
},
}),
}),
});

export const { useSubmitDataMutation } = submitApi;
export const {
useSubmitDataMutation,
useFetchSavedMetadataQuery
} = submitApi;
3 changes: 0 additions & 3 deletions packages/deposit/src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import metadataReducer from "../features/metadata/metadataSlice";
import filesReducer from "../features/files/filesSlice";
import submitReducer from "../features/submit/submitSlice";
import depositReducer from "../deposit/depositSlice";
import { depositApi } from "../deposit/depositApi";
import { orcidApi } from "../features/metadata/api/orcid";
import { rorApi } from "../features/metadata/api/ror";
import { gettyApi } from "../features/metadata/api/getty";
Expand Down Expand Up @@ -37,7 +36,6 @@ export const store = configureStore({
[dansUtilityApi.reducerPath]: dansUtilityApi.reducer,
[rdaApi.reducerPath]: rdaApi.reducer,
[languagesApi.reducerPath]: languagesApi.reducer,
[depositApi.reducerPath]: depositApi.reducer,
[validateKeyApi.reducerPath]: validateKeyApi.reducer,
submit: submitReducer,
deposit: depositReducer,
Expand All @@ -57,7 +55,6 @@ export const store = configureStore({
.concat(dansUtilityApi.middleware)
.concat(rdaApi.middleware)
.concat(languagesApi.middleware)
.concat(depositApi.middleware)
.concat(validateKeyApi.middleware)
.concat(errorLogger),
});
Expand Down

0 comments on commit d53c1bf

Please sign in to comment.