Skip to content

Commit

Permalink
chore: add publisherId to posts
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsOveTen committed Sep 21, 2023
1 parent 517fb1b commit 2b2beb0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/features/conceptForm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const postNewConcept = createAsyncThunk<
PostNewAttributes,
RejectValue
>('conceptForm/postNewConcept', async ({ concept }, { rejectWithValue }) =>
postConceptWithPreProcess(concept)
postConceptWithPreProcess(concept.ansvarligVirksomhet.id, concept)
.then(response => response)
.catch(() => rejectWithValue(true))
);
Expand Down
15 changes: 10 additions & 5 deletions src/pages/concept-registration-page/form-concept/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import { getConfig } from '../../../config';
import { setValidationError } from '../../../features/conceptForm';

export const validateWithPreProcess = (values, { dispatch }) => {
const processedValues = preProcessValues(values);
const processedValues = preProcessValues(
values.ansvarligVirksomhet.id,
values
);

return validateYupSchema(processedValues, validationSchema)
.then(() => {
Expand Down Expand Up @@ -157,10 +160,12 @@ export const FormConceptPure: FC<Props> = ({
};

const createNewConceptRevisionAndNavigate = () =>
postConceptRevisionWithPreProcess(conceptId, values).then(resourceId => {
setShowUserPrompt(false);
history.push(`/${catalogId}/${resourceId}`);
});
postConceptRevisionWithPreProcess(conceptId, publisherId, values).then(
resourceId => {
setShowUserPrompt(false);
history.push(`/${catalogId}/${resourceId}`);
}
);

useEffect(() => {
const handler = event => {
Expand Down
33 changes: 21 additions & 12 deletions src/pages/concept-registration-page/form-concept/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,40 @@ const pruneEmptyProperties = (obj: any, reduceAsArray = false) => {
}, {});
};

export const preProcessValues = ({
merknad,
eksempel,
fagområde,
omfang,
kontaktpunkt,
...conceptValues
}) => ({
export const preProcessValues = (
orgId: string,
{
ansvarligVirksomhet,
merknad,
eksempel,
fagområde,
omfang,
kontaktpunkt,
...conceptValues
}
) => ({
...conceptValues,
merknad: merknad ? stringsToArray(merknad) : null,
eksempel: eksempel ? stringsToArray(eksempel) : null,
fagområde: fagområde ? stringsToArray(fagområde) : null,
omfang: pruneEmptyProperties(omfang),
kontaktpunkt: pruneEmptyProperties(kontaktpunkt)
kontaktpunkt: pruneEmptyProperties(kontaktpunkt),
ansvarligVirksomhet: ansvarligVirksomhet || { id: orgId }
});

export const postConceptWithPreProcess = async (values): Promise<string> => {
const processedValues = preProcessValues(values);
export const postConceptWithPreProcess = async (
publisherId: string,
values
): Promise<string> => {
const processedValues = preProcessValues(publisherId, values);
return postConcept(processedValues);
};

export const postConceptRevisionWithPreProcess = async (
id: string,
publisherId: string,
values
): Promise<void> => {
const processedValues = preProcessValues(values);
const processedValues = preProcessValues(publisherId, values);
return postConceptRevision(id, processedValues);
};

0 comments on commit 2b2beb0

Please sign in to comment.