|
| 1 | +interface Error { |
| 2 | + message: string |
| 3 | + code: string |
| 4 | +} |
| 5 | + |
| 6 | +const POLARIS_STYLESHEET_URL = 'https://unpkg.com/@shopify/polaris@13.9.2/build/esm/styles.css' |
| 7 | + |
| 8 | +function escapeHtml(unsafe: string) { |
| 9 | + return unsafe |
| 10 | + .replace(/&/g, '&') |
| 11 | + .replace(/</g, '<') |
| 12 | + .replace(/>/g, '>') |
| 13 | + .replace(/"/g, '"') |
| 14 | + .replace(/'/g, ''') |
| 15 | +} |
| 16 | + |
| 17 | +export function getErrorPage(options: {title: string; header: string; errors: Error[]}) { |
| 18 | + const html = String.raw |
| 19 | + return html`<!DOCTYPE html> |
| 20 | + <html> |
| 21 | + <head> |
| 22 | + <title>${options.title ?? 'Upload Errors'}</title> |
| 23 | + <link rel="stylesheet" href="${POLARIS_STYLESHEET_URL}" /> |
| 24 | + </head> |
| 25 | + <body> |
| 26 | + <div style="display: flex; justify-content: center; padding-top: 2rem;"> |
| 27 | + <div style="width: 80%;"> |
| 28 | + <div class="Polaris-Banner Polaris-Banner--withinPage" tabindex="0" role="alert" aria-live="polite"> |
| 29 | + <div class="Polaris-Box" style="--pc-box-width:100%"> |
| 30 | + <div |
| 31 | + class="Polaris-BlockStack" |
| 32 | + style="--pc-block-stack-align:space-between;--pc-block-stack-order:column" |
| 33 | + > |
| 34 | + <div |
| 35 | + class="Polaris-Box" |
| 36 | + style="--pc-box-color: var(--p-color-text-critical-on-bg-fill); --pc-box-background: var(--p-color-bg-fill-critical); --pc-box-padding-block-start-xs: var(--p-space-300); --pc-box-padding-block-end-xs: var(--p-space-300); --pc-box-padding-inline-start-xs: var(--p-space-300); --pc-box-padding-inline-end-xs: var(--p-space-300); --pc-box-border-start-start-radius: var(--p-border-radius-300); --pc-box-border-start-end-radius: var(--p-border-radius-300);" |
| 37 | + > |
| 38 | + <div |
| 39 | + class="Polaris-InlineStack" |
| 40 | + style="--pc-inline-stack-align:space-between;--pc-inline-stack-block-align:center;--pc-inline-stack-wrap:nowrap;--pc-inline-stack-gap-xs:var(--p-space-200);--pc-inline-stack-flex-direction-xs:row" |
| 41 | + > |
| 42 | + <div |
| 43 | + class="Polaris-InlineStack" |
| 44 | + style="--pc-inline-stack-wrap:nowrap;--pc-inline-stack-gap-xs:var(--p-space-100);--pc-inline-stack-flex-direction-xs:row" |
| 45 | + > |
| 46 | + <span class="Polaris-Banner--textCriticalOnBgFill"> |
| 47 | + <span class="Polaris-Icon"> |
| 48 | + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"> |
| 49 | + <path d="M10 6a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5a.75.75 0 0 1 .75-.75Z" /> |
| 50 | + <path d="M11 13a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z" /> |
| 51 | + <path |
| 52 | + fill-rule="evenodd" |
| 53 | + d="M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Zm-1.5 0a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0Z" |
| 54 | + /> |
| 55 | + </svg> |
| 56 | + </span> |
| 57 | + </span> |
| 58 | + <h2 class="Polaris-Text--root Polaris-Text--headingSm Polaris-Text--break"> |
| 59 | + ${options.header} |
| 60 | + </h2> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + <div |
| 65 | + class="Polaris-Box" |
| 66 | + style="--pc-box-padding-block-start-xs:var(--p-space-300);--pc-box-padding-block-end-xs:var(--p-space-300);--pc-box-padding-block-end-md:var(--p-space-400);--pc-box-padding-inline-start-xs:var(--p-space-300);--pc-box-padding-inline-start-md:var(--p-space-400);--pc-box-padding-inline-end-xs:var(--p-space-300);--pc-box-padding-inline-end-md:var(--p-space-400)" |
| 67 | + > |
| 68 | + <div |
| 69 | + class="Polaris-BlockStack" |
| 70 | + style="--pc-block-stack-order:column;--pc-block-stack-gap-xs:var(--p-space-300)" |
| 71 | + > |
| 72 | + ${options.errors |
| 73 | + .map( |
| 74 | + (error) => ` |
| 75 | + <div> |
| 76 | + <span class="Polaris-Text--root Polaris-Text--headingSm">${escapeHtml(error.message)}</span> |
| 77 | + <ul class="Polaris-List"> |
| 78 | + <li class="Polaris-List__Item">${escapeHtml(error.code)}</li> |
| 79 | + </ul> |
| 80 | + </div>`, |
| 81 | + ) |
| 82 | + .join('')} |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </body> |
| 91 | + </html>` |
| 92 | +} |
0 commit comments