Skip to content

Commit

Permalink
Endringer etter PR
Browse files Browse the repository at this point in the history
  • Loading branch information
magnurh-cx committed Jan 17, 2025
1 parent babb034 commit b2fe09c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/bygger-backend/src/fetchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export async function fetchWithErrorHandling(url: RequestInfo, options: RequestI
};
}

const logMeta = { status: res.status, method };
logger.warn(`Fetch ${method} ${url}: Unexpected content-type "${res.headers.get('content-type')}"`, logMeta);
return {
status: 'OK',
data: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const post: RequestHandler = async (req, res, next) => {
const body = { key, tag, nb, nn, en };
try {
const translation = await globalTranslationsService.post(body, accessToken);
res.status(201).json(translation);
res.status(204).json(translation);
} catch (error) {
if (error instanceof OldHttpError) {
next(new HttpError(error.message, error.response.status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
TranslationResource,
} from '@navikt/skjemadigitalisering-shared-domain';

// We need to map to this deprecated format as long as we still use gitHub for publishing. When published translations are collected from forms-api this can be removed.
// Note that tag here is not used, as it is superfluous. All tags have been combined into one, named 'dummy-tag'
const mapGlobalToFormioFormat = ({ translations }: PublishedTranslations): GlobalTranslationsResourceContent => {
const resourceDefaults: Pick<TranslationResource, 'id' | 'name' | 'scope' | 'tag'> = {
id: '',
Expand Down
6 changes: 4 additions & 2 deletions packages/bygger/src/api/useGlobalTranslationsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ const useGlobalTranslationsApi = () => {

const publish = async () => {
try {
return await http.post(`${basePath}/publish`, {});
await http.post(`${basePath}/publish`, {});
feedbackEmit.success(
'Publisering av globale oversettelser fullført. Endringene vil bli synlige på nav.no/fyllut om noen minutter.',
);
} catch (error: any) {
const message = (error as Error)?.message;
feedbackEmit.error(`Feil ved publisering. ${message}`);
throw error;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ const GlobalTranslationsProvider = ({ children }) => {
feedbackEmit.error(getMissingGlobalTranslationsErrorMessage(tagsWithMissingTranslations));
} else {
await translationsApi.publish();
feedbackEmit.success(
'Publisering av globale oversettelser fullført. Endringene vil bli synlige på nav.no/fyllut om noen minutter.',
);
await loadTranslations();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useGlobalTranslations } from '../../context/translations/GlobalTranslat
const GlobalTranslationButtonsColumn = () => {
const [isProcessing, setIsProcessing] = useState<'SAVING' | 'PUBLISHING'>();
const { saveChanges } = useEditGlobalTranslations();
const { publish, loadTranslations } = useGlobalTranslations();
const { publish } = useGlobalTranslations();

const handleSave = async () => {
try {
Expand All @@ -19,13 +19,9 @@ const GlobalTranslationButtonsColumn = () => {
};

const handlePublish = async () => {
try {
setIsProcessing('PUBLISHING');
await publish();
await loadTranslations();
} finally {
setIsProcessing(undefined);
}
setIsProcessing('PUBLISHING');
await publish();
setIsProcessing(undefined);
};

return (
Expand Down

0 comments on commit b2fe09c

Please sign in to comment.