mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 11:00:47 +02:00
Add frontend autoformatting and set CI to require formatted code for all languages (#6052)
# Description of Changes Changes the strategy for autoformatting to reject PRs if they are not formatted correctly instead of allowing them to merge and then spawning a new PR to fix the formatting. The old strategy just caused more work for us because we'd have to manually approve the followup PR and get it merged, which required 2 reviewers so in practice it rarely got done and just meant everyone's PRs ended up containing reformatting for unrelated files, which makes code review unnecessarily difficult. If the PR's code is not formatted correctly after this PR, a comment will be added automatically to tell the author how to run the formatter script to fix their code so it can go in. This also enables autoformatting for the frontend code, using Prettier. I've enabled it for pretty much everything in the frontend folder, other than 3rd party files and files it doesn't make sense for. I also excluded Markdown because it sounds likely to be more annoying to have to autoformat the Markdown in the frontend folder but nowhere else. Open to changing this though if people disagree. > [!note] > > Advice to reviewers: The first commit contains all of the actual logic I've introduced (CI changes, Prettier config, etc.) > The second commit is just the reformatting of the entire frontend folder. > The first commit needs proper review, the second one just give it a spot-check that it's doing what you'd expect.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { isAxiosError } from 'axios';
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import { isAxiosError } from "axios";
|
||||
import workflowService, {
|
||||
WorkflowSessionResponse,
|
||||
ParticipantResponse,
|
||||
SignatureSubmissionRequest,
|
||||
} from '@app/services/workflowService';
|
||||
} from "@app/services/workflowService";
|
||||
|
||||
export interface UseParticipantSessionResult {
|
||||
session: WorkflowSessionResponse | null;
|
||||
@@ -38,8 +38,8 @@ export const useParticipantSession = (token?: string): UseParticipantSessionResu
|
||||
setParticipant(participantData);
|
||||
} catch (err: unknown) {
|
||||
const errorMsg = isAxiosError(err)
|
||||
? (err.response?.data?.message || err.message)
|
||||
: (err instanceof Error ? err.message : undefined) || 'Failed to load session';
|
||||
? err.response?.data?.message || err.message
|
||||
: (err instanceof Error ? err.message : undefined) || "Failed to load session";
|
||||
setError(errorMsg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -59,15 +59,15 @@ export const useParticipantSession = (token?: string): UseParticipantSessionResu
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
const errorMsg = isAxiosError(err)
|
||||
? (err.response?.data?.message || err.message)
|
||||
: (err instanceof Error ? err.message : undefined) || 'Failed to submit signature';
|
||||
? err.response?.data?.message || err.message
|
||||
: (err instanceof Error ? err.message : undefined) || "Failed to submit signature";
|
||||
setError(errorMsg);
|
||||
throw new Error(errorMsg, { cause: err });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[loadSession]
|
||||
[loadSession],
|
||||
);
|
||||
|
||||
const decline = useCallback(
|
||||
@@ -75,48 +75,48 @@ export const useParticipantSession = (token?: string): UseParticipantSessionResu
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const updatedParticipant = await workflowService.declineParticipation(
|
||||
token,
|
||||
reason
|
||||
);
|
||||
const updatedParticipant = await workflowService.declineParticipation(token, reason);
|
||||
setParticipant(updatedParticipant);
|
||||
// Reload session
|
||||
await loadSession(token);
|
||||
} catch (err: unknown) {
|
||||
const errorMsg = isAxiosError(err)
|
||||
? (err.response?.data?.message || err.message)
|
||||
: (err instanceof Error ? err.message : undefined) || 'Failed to decline';
|
||||
? err.response?.data?.message || err.message
|
||||
: (err instanceof Error ? err.message : undefined) || "Failed to decline";
|
||||
setError(errorMsg);
|
||||
throw new Error(errorMsg, { cause: err });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[loadSession]
|
||||
[loadSession],
|
||||
);
|
||||
|
||||
const downloadDocument = useCallback(async (token: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const pdfBlob = await workflowService.getParticipantDocument(token);
|
||||
const url = window.URL.createObjectURL(pdfBlob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = session?.documentName || 'document.pdf';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
} catch (err: unknown) {
|
||||
const errorMsg = isAxiosError(err)
|
||||
? (err.response?.data?.message || err.message)
|
||||
: (err instanceof Error ? err.message : undefined) || 'Failed to download document';
|
||||
setError(errorMsg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [session]);
|
||||
const downloadDocument = useCallback(
|
||||
async (token: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const pdfBlob = await workflowService.getParticipantDocument(token);
|
||||
const url = window.URL.createObjectURL(pdfBlob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = session?.documentName || "document.pdf";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
} catch (err: unknown) {
|
||||
const errorMsg = isAxiosError(err)
|
||||
? err.response?.data?.message || err.message
|
||||
: (err instanceof Error ? err.message : undefined) || "Failed to download document";
|
||||
setError(errorMsg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[session],
|
||||
);
|
||||
|
||||
// Auto-load session if token is provided
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user