-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'donskov/v2' into aslobodian/v2-add-certificate-creation…
…-dialog
- Loading branch information
Showing
18 changed files
with
1,774 additions
and
941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Main CI | ||
on: [workflow_dispatch, push] | ||
jobs: | ||
tests_checks_build: | ||
runs-on: ubuntu-latest | ||
name: Tests, checks, build | ||
steps: | ||
- uses: actions/checkout@v4 | ||
name: Checkout | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'yarn' | ||
name: Setup node | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Run linter | ||
run: yarn lint | ||
- name: Run tests | ||
run: yarn test:ci | ||
- name: Run build | ||
run: yarn build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/components/certificate-import-dialog/CertificateImportDialog.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { fn } from "@storybook/test"; | ||
import { CertificateImportDialog } from "./CertificateImportDialog"; | ||
|
||
const meta: Meta<typeof CertificateImportDialog> = { | ||
title: "Components/CertificateImportDialog", | ||
component: CertificateImportDialog, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof CertificateImportDialog>; | ||
|
||
const providers = [ | ||
{ | ||
id: "1", | ||
name: "Provider 1", | ||
}, | ||
{ | ||
id: "2", | ||
name: "Provider 2", | ||
}, | ||
]; | ||
|
||
export const Default: Story = { | ||
args: { | ||
currentProviderId: "2", | ||
providers, | ||
onProviderSelect: fn(), | ||
onTextAreaChange: fn(), | ||
}, | ||
}; | ||
|
||
export const isLoading: Story = { | ||
args: { | ||
loading: true, | ||
providers, | ||
onProviderSelect: fn(), | ||
}, | ||
}; |
225 changes: 225 additions & 0 deletions
225
src/components/certificate-import-dialog/CertificateImportDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
import React from "react"; | ||
import { useDropzone } from "react-dropzone"; | ||
import { Trans, useTranslation } from "react-i18next"; | ||
import { IProviderInfo } from "@peculiar/fortify-client-core"; | ||
import clsx from "clsx"; | ||
import { | ||
Dialog, | ||
ArrowRightIcon, | ||
IconButton, | ||
Typography, | ||
TextareaField, | ||
Button, | ||
CircularProgress, | ||
} from "@peculiar/react-components"; | ||
import { CertificatesProvidersSelectList } from "../certificates-providers-select-list"; | ||
import { formatBytes } from "../../utils"; | ||
|
||
import CrossIcon from "../../icons/cross.svg?react"; | ||
|
||
import styles from "./styles/index.module.scss"; | ||
|
||
import { | ||
APP_CERTIFICATE_ALLOWED_MIMES, | ||
APP_CERTIFICATE_MAX_SIZE_BYTES, | ||
} from "../../config"; | ||
|
||
interface CertificateImportDialogProps { | ||
currentProviderId?: string; | ||
providers: Pick<IProviderInfo, "id" | "name">[]; | ||
loading?: boolean; | ||
certificate: string; | ||
isTextAreaError: boolean; | ||
onTextAreaChange: (certificate: string) => void; | ||
onTextAreaBlur: () => void; | ||
onProviderSelect: (id: string) => void; | ||
onDialogClose: () => void; | ||
onImportButtonClick: () => void; | ||
onDropError: (error?: unknown) => void; | ||
onDropRejected: (error: string) => void; | ||
onDropAccepted: (fileContent: ArrayBuffer) => void; | ||
onClearButtonClick: () => void; | ||
} | ||
|
||
export const CertificateImportDialog: React.FunctionComponent< | ||
CertificateImportDialogProps | ||
> = (props) => { | ||
const { | ||
loading, | ||
providers, | ||
currentProviderId, | ||
certificate, | ||
isTextAreaError, | ||
onTextAreaChange, | ||
onTextAreaBlur, | ||
onProviderSelect, | ||
onDialogClose, | ||
onImportButtonClick, | ||
onDropError, | ||
onDropRejected, | ||
onDropAccepted, | ||
onClearButtonClick, | ||
} = props; | ||
|
||
const { t } = useTranslation(); | ||
|
||
const { getRootProps, isDragActive, isDragReject } = useDropzone({ | ||
multiple: false, | ||
accept: APP_CERTIFICATE_ALLOWED_MIMES, | ||
maxSize: APP_CERTIFICATE_MAX_SIZE_BYTES, | ||
onDropRejected: ([file]) => { | ||
file.errors.forEach((err) => { | ||
let msg; | ||
if (err.code === "file-too-large") { | ||
msg = t("certificates.dialog.import.file.error.too-large", { | ||
size: formatBytes(APP_CERTIFICATE_MAX_SIZE_BYTES), | ||
}); | ||
} | ||
if (err.code === "file-invalid-type") { | ||
msg = t("certificates.dialog.import.file.error.invalid-type"); | ||
} | ||
|
||
if (msg) { | ||
onDropRejected(msg); | ||
} | ||
}); | ||
}, | ||
onDropAccepted: ([file]) => { | ||
if (!file) { | ||
return false; | ||
} | ||
const reader = new FileReader(); | ||
|
||
reader.readAsArrayBuffer(file); | ||
|
||
reader.onload = (event) => { | ||
try { | ||
onDropAccepted(event.target?.result as ArrayBuffer); | ||
} catch (error) { | ||
onDropError(error); | ||
} | ||
}; | ||
|
||
reader.onerror = onDropError; | ||
}, | ||
onError: onDropError, | ||
}); | ||
|
||
return ( | ||
<Dialog open fullScreen className={styles.dialog} onClose={onDialogClose}> | ||
<> | ||
<div className={styles.title}> | ||
<div className={styles.centered}> | ||
<div> | ||
<IconButton | ||
onClick={onDialogClose} | ||
className={styles.button_back} | ||
size="small" | ||
> | ||
<ArrowRightIcon className={styles.arrow_back} /> | ||
</IconButton> | ||
</div> | ||
<div className={styles.title_label}> | ||
<Typography variant="h4" color="black"> | ||
{t("certificates.dialog.import.title")} | ||
</Typography> | ||
</div> | ||
<div> | ||
<CertificatesProvidersSelectList | ||
providers={providers} | ||
currentProviderId={currentProviderId} | ||
onSelect={onProviderSelect} | ||
className={styles.provider_select} | ||
popoverClassName={styles.provider_select_popover} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className={styles.content}> | ||
<div className={clsx(styles.centered, styles.content_box)}> | ||
<div | ||
{...getRootProps({ | ||
className: clsx(styles.drop_zone, { | ||
[styles.drop_zone_active]: isDragActive, | ||
[styles.drop_zone_reject]: isDragReject, | ||
}), | ||
})} | ||
> | ||
<Typography variant="s2" color="gray-10"> | ||
<Trans | ||
i18nKey="certificates.dialog.import.drop-zone.title" | ||
components={[ | ||
<Typography | ||
className={styles.drop_zone_title_link} | ||
color="primary" | ||
variant="s2" | ||
component="button" | ||
> | ||
{0} | ||
</Typography>, | ||
]} | ||
/> | ||
</Typography> | ||
<Typography variant="c2" color="gray-9"> | ||
{t("certificates.dialog.import.drop-zone.description")} | ||
</Typography> | ||
</div> | ||
<div className={styles.divider_form}> | ||
<Typography | ||
variant="s2" | ||
className={styles.divider_form_inner} | ||
color="gray-10" | ||
> | ||
{t("certificates.dialog.import.divider-label")} | ||
</Typography> | ||
</div> | ||
<div> | ||
<TextareaField | ||
className={styles.text_area} | ||
value={certificate} | ||
onChange={(event) => onTextAreaChange(event.target.value)} | ||
size="large" | ||
onBlur={onTextAreaBlur} | ||
error={isTextAreaError} | ||
errorText={ | ||
isTextAreaError | ||
? t( | ||
"certificates.dialog.import.certificate.error.invalid-data" | ||
) | ||
: undefined | ||
} | ||
/> | ||
</div> | ||
<div className={styles.buttons_group}> | ||
<Button | ||
variant="outlined" | ||
startIcon={<CrossIcon />} | ||
disabled={!certificate?.length} | ||
onClick={onClearButtonClick} | ||
className={styles.cancel_button} | ||
> | ||
{t("button.clear")} | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
disabled={!certificate?.length || isTextAreaError} | ||
onClick={onImportButtonClick} | ||
> | ||
{t("button.import-certificate")} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
{loading ? ( | ||
<div className={styles.loading}> | ||
<CircularProgress /> | ||
<Typography variant="b2" color="gray-9"> | ||
{t("certificates.dialog.import.loading-text")} | ||
</Typography> | ||
</div> | ||
) : null} | ||
</> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./CertificateImportDialog"; |
Oops, something went wrong.