Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/deploy-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
cache: "pnpm"

- name: Install and Build
env:
VITE_API_BASE_URL: https://esign-demo-proxy-server-191591660773.us-central1.run.app
run: |
pnpm install
rm -rf dist
Expand Down
6 changes: 4 additions & 2 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import CustomSignature from './CustomSignature';
import 'superdoc/style.css';
import './App.css';

const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';

const documentSource =
'https://storage.googleapis.com/public_static_hosting/public_demo_docs/service_agreement_updated.docx';

Expand Down Expand Up @@ -91,7 +93,7 @@ export function App() {
console.log('Submit data:', data);

try {
const response = await fetch('/v1/sign', {
const response = await fetch(`${API_BASE_URL}/v1/sign`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
Expand Down Expand Up @@ -132,7 +134,7 @@ export function App() {
return;
}

const response = await fetch('/v1/download', {
const response = await fetch(`${API_BASE_URL}/v1/download`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
Expand Down
24 changes: 18 additions & 6 deletions src/defaults/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@ import React from 'react';
import type { DownloadButtonProps, DownloadConfig } from '../types';

export const createDownloadButton = (config?: DownloadConfig) => {
const Component: React.FC<DownloadButtonProps> = ({ onClick, fileName, isDisabled }) => {
const Component: React.FC<DownloadButtonProps> = ({
onClick,
fileName,
isDisabled,
isDownloading,
}) => {
const label = config?.label || 'Download';
const disabled = isDisabled || isDownloading;

return (
<button
onClick={onClick}
disabled={isDisabled}
className={`superdoc-esign-btn superdoc-esign-btn--download`}
disabled={disabled}
className={`superdoc-esign-btn superdoc-esign-btn--download${isDownloading ? ' superdoc-esign-btn--loading' : ''}`}
style={{
padding: '8px 16px',
borderRadius: '6px',
border: '1px solid #d0d5dd',
background: '#ffffff',
color: '#333',
cursor: isDisabled ? 'not-allowed' : 'pointer',
opacity: isDisabled ? 0.5 : 1,
cursor: disabled ? 'not-allowed' : 'pointer',
opacity: disabled ? 0.7 : 1,
fontSize: '16px',
fontWeight: 'bold',
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
transition: 'opacity 0.2s ease',
}}
>
{label} {fileName && `(${fileName})`}
{isDownloading && <span className="superdoc-esign-spinner" />}
{isDownloading ? 'Downloading...' : label}
{!isDownloading && fileName && ` (${fileName})`}
</button>
);
};
Expand Down
20 changes: 12 additions & 8 deletions src/defaults/SubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ export const createSubmitButton = (config?: SubmitConfig) => {
isDisabled,
isSubmitting,
}) => {
const getLabel = () => {
return config?.label || 'Submit';
};
const label = config?.label || 'Submit';
const disabled = !isValid || isDisabled || isSubmitting;

return (
<button
onClick={onClick}
disabled={!isValid || isDisabled || isSubmitting}
className={`superdoc-esign-btn superdoc-esign-btn--submit`}
disabled={disabled}
className={`superdoc-esign-btn superdoc-esign-btn--submit${isSubmitting ? ' superdoc-esign-btn--loading' : ''}`}
style={{
padding: '12px 24px',
borderRadius: '6px',
border: 'none',
background: '#007bff',
color: '#fff',
cursor: !isValid || isDisabled ? 'not-allowed' : 'pointer',
opacity: !isValid || isDisabled ? 0.5 : 1,
cursor: disabled ? 'not-allowed' : 'pointer',
opacity: disabled && !isSubmitting ? 0.5 : 1,
fontSize: '16px',
fontWeight: 'bold',
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
transition: 'opacity 0.2s ease',
}}
>
{getLabel()}
{isSubmitting && <span className="superdoc-esign-spinner superdoc-esign-spinner--light" />}
{isSubmitting ? 'Submitting...' : label}
</button>
);
};
Expand Down
23 changes: 20 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
const [fieldValues, setFieldValues] = useState<Map<string, Types.FieldValue>>(new Map());
const [isValid, setIsValid] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [isDownloading, setIsDownloading] = useState(false);
const [auditTrail, setAuditTrail] = useState<Types.AuditEvent[]>([]);
const [isReady, setIsReady] = useState(false);

Expand Down Expand Up @@ -129,7 +130,7 @@
});

const discovered: Types.FieldInfo[] = tags
.map(({ node }: any) => ({

Check warning on line 133 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

Unexpected any. Specify a different type
id: node.attrs.id,
label: node.attrs.label,
value: configValues.get(node.attrs.id) ?? node.textContent ?? '',
Expand Down Expand Up @@ -162,7 +163,7 @@
...event,
timestamp: new Date().toISOString(),
};
const auditMock = (globalThis as any)?.__SUPERDOC_AUDIT_MOCK__;

Check warning on line 166 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

Unexpected any. Specify a different type
if (auditMock) {
auditMock(auditEvent);
}
Expand Down Expand Up @@ -298,7 +299,9 @@
}, [scrolled, fieldValues, isSubmitting, checkIsValid, onStateChange]);

const handleDownload = useCallback(async () => {
if (isDisabled) return;
if (isDisabled || isDownloading) return;

setIsDownloading(true);

const downloadData: Types.DownloadData = {
eventId,
Expand All @@ -313,8 +316,21 @@
fileName: download?.fileName || 'document.pdf',
};

await onDownload?.(downloadData);
}, [isDisabled, eventId, document.source, fields, fieldValues, download, onDownload]);
try {
await onDownload?.(downloadData);
} finally {
setIsDownloading(false);
}
}, [
isDisabled,
isDownloading,
eventId,
document.source,
fields,
fieldValues,
download,
onDownload,
]);

const handleSubmit = useCallback(async () => {
if (!isValid || isDisabled || isSubmitting) return;
Expand Down Expand Up @@ -378,6 +394,7 @@
onClick={handleDownload}
fileName={download?.fileName}
isDisabled={isDisabled}
isDownloading={isDownloading}
/>
);
};
Expand Down
26 changes: 26 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,29 @@
display: flex;
gap: 10px;
}

/* Button loading state */
.superdoc-esign-btn--loading {
position: relative;
}

/* Spinner */
.superdoc-esign-spinner {
width: 16px;
height: 16px;
border: 2px solid #d0d5dd;
border-top-color: #333;
border-radius: 50%;
animation: superdoc-esign-spin 0.8s linear infinite;
}

.superdoc-esign-spinner--light {
border-color: rgba(255, 255, 255, 0.3);
border-top-color: #fff;
}

@keyframes superdoc-esign-spin {
to {
transform: rotate(360deg);
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface DownloadButtonProps {
onClick: () => void;
fileName?: string;
isDisabled: boolean;
isDownloading: boolean;
}

export interface SubmitButtonProps {
Expand Down
Loading