mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
fix(console): should be able to remove the zip on upload error (#6306)
This commit is contained in:
parent
27e0d36e64
commit
32e33487bd
3 changed files with 8 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { type CustomUiAssets, maxUploadFileSize, type AllowedUploadMimeType } from '@logto/schemas';
|
import { type CustomUiAssets, maxUploadFileSize, type AllowedUploadMimeType } from '@logto/schemas';
|
||||||
|
import { type Nullable } from '@silverhand/essentials';
|
||||||
import { format } from 'date-fns/fp';
|
import { format } from 'date-fns/fp';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
@ -13,15 +14,15 @@ import FileIcon from '../FileIcon';
|
||||||
import * as styles from './index.module.scss';
|
import * as styles from './index.module.scss';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
readonly value?: CustomUiAssets;
|
|
||||||
readonly onChange: (value: CustomUiAssets) => void;
|
|
||||||
// eslint-disable-next-line react/boolean-prop-naming
|
// eslint-disable-next-line react/boolean-prop-naming
|
||||||
readonly disabled?: boolean;
|
readonly disabled?: boolean;
|
||||||
|
readonly value: Nullable<CustomUiAssets>;
|
||||||
|
readonly onChange: (value: Nullable<CustomUiAssets>) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const allowedMimeTypes: AllowedUploadMimeType[] = ['application/zip'];
|
const allowedMimeTypes: AllowedUploadMimeType[] = ['application/zip'];
|
||||||
|
|
||||||
function CustomUiAssetsUploader({ value, onChange, disabled }: Props) {
|
function CustomUiAssetsUploader({ disabled, value, onChange }: Props) {
|
||||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
const [file, setFile] = useState<File>();
|
const [file, setFile] = useState<File>();
|
||||||
const [error, setError] = useState<string>();
|
const [error, setError] = useState<string>();
|
||||||
|
@ -79,7 +80,7 @@ function CustomUiAssetsUploader({ value, onChange, disabled }: Props) {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setFile(undefined);
|
setFile(undefined);
|
||||||
setError(undefined);
|
setError(undefined);
|
||||||
onChange({ id: '', createdAt: 0 });
|
onChange(null);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
|
|
|
@ -49,14 +49,13 @@ export const signUpFormDataParser = {
|
||||||
|
|
||||||
export const sieFormDataParser = {
|
export const sieFormDataParser = {
|
||||||
fromSignInExperience: (data: SignInExperience): SignInExperienceForm => {
|
fromSignInExperience: (data: SignInExperience): SignInExperienceForm => {
|
||||||
const { signUp, signInMode, customCss, customUiAssets, branding, passwordPolicy } = data;
|
const { signUp, signInMode, customCss, branding, passwordPolicy } = data;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
signUp: signUpFormDataParser.fromSignUp(signUp),
|
signUp: signUpFormDataParser.fromSignUp(signUp),
|
||||||
createAccountEnabled: signInMode !== SignInMode.SignIn,
|
createAccountEnabled: signInMode !== SignInMode.SignIn,
|
||||||
customCss: customCss ?? undefined,
|
customCss: customCss ?? undefined,
|
||||||
customUiAssets: customUiAssets ?? undefined,
|
|
||||||
branding: {
|
branding: {
|
||||||
...emptyBranding,
|
...emptyBranding,
|
||||||
...branding,
|
...branding,
|
||||||
|
@ -86,7 +85,6 @@ export const sieFormDataParser = {
|
||||||
signUp: signUpFormDataParser.toSignUp(signUp),
|
signUp: signUpFormDataParser.toSignUp(signUp),
|
||||||
signInMode: createAccountEnabled ? SignInMode.SignInAndRegister : SignInMode.SignIn,
|
signInMode: createAccountEnabled ? SignInMode.SignInAndRegister : SignInMode.SignIn,
|
||||||
customCss: customCss?.length ? customCss : null,
|
customCss: customCss?.length ? customCss : null,
|
||||||
customUiAssets: customUiAssets?.id ? customUiAssets : null,
|
|
||||||
passwordPolicy: {
|
passwordPolicy: {
|
||||||
...passwordPolicy,
|
...passwordPolicy,
|
||||||
rejects: {
|
rejects: {
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
import { type PasswordPolicy } from '@logto/core-kit';
|
import { type PasswordPolicy } from '@logto/core-kit';
|
||||||
import {
|
import { type SignUp, type SignInExperience, type SignInIdentifier } from '@logto/schemas';
|
||||||
type SignUp,
|
|
||||||
type SignInExperience,
|
|
||||||
type SignInIdentifier,
|
|
||||||
type CustomUiAssets,
|
|
||||||
} from '@logto/schemas';
|
|
||||||
|
|
||||||
export enum SignInExperienceTab {
|
export enum SignInExperienceTab {
|
||||||
Branding = 'branding',
|
Branding = 'branding',
|
||||||
|
@ -27,10 +22,9 @@ export type SignUpForm = Omit<SignUp, 'identifiers'> & {
|
||||||
|
|
||||||
export type SignInExperienceForm = Omit<
|
export type SignInExperienceForm = Omit<
|
||||||
SignInExperience,
|
SignInExperience,
|
||||||
'signUp' | 'customCss' | 'customUiAssets' | 'passwordPolicy'
|
'signUp' | 'customCss' | 'passwordPolicy'
|
||||||
> & {
|
> & {
|
||||||
customCss?: string; // Code editor components can not properly handle null value, manually transform null to undefined instead.
|
customCss?: string; // Code editor components can not properly handle null value, manually transform null to undefined instead.
|
||||||
customUiAssets?: CustomUiAssets;
|
|
||||||
signUp: SignUpForm;
|
signUp: SignUpForm;
|
||||||
/** The parsed password policy object. All properties are required. */
|
/** The parsed password policy object. All properties are required. */
|
||||||
passwordPolicy: PasswordPolicy & {
|
passwordPolicy: PasswordPolicy & {
|
||||||
|
|
Loading…
Reference in a new issue