2023-01-16 09:31:36 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
|
|
|
|
|
|
|
// Lazy loaded components
|
|
|
|
|
|
|
|
const CheckCircleFilled = dynamic(() => import('@ant-design/icons/CheckCircleFilled'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ExclamationCircleFilled = dynamic(() => import('@ant-design/icons/ExclamationCircleFilled'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const LoadingOutlined = dynamic(() => import('@ant-design/icons/LoadingOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const WarningOutlined = dynamic(() => import('@ant-design/icons/WarningOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
2021-01-31 06:33:01 +03:00
|
|
|
|
|
|
|
export const STATUS_RESET_TIMEOUT = 3000;
|
|
|
|
|
|
|
|
export const STATUS_ERROR = 'error';
|
|
|
|
export const STATUS_INVALID = 'invalid';
|
|
|
|
export const STATUS_PROCESSING = 'proessing';
|
|
|
|
export const STATUS_SUCCESS = 'success';
|
|
|
|
export const STATUS_WARNING = 'warning';
|
|
|
|
|
2021-02-01 08:36:14 +03:00
|
|
|
export type InputStatusTypes = 'error' | 'invalid' | 'proessing' | 'success' | 'warning';
|
2021-01-31 06:33:01 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
export interface StatusState {
|
2021-01-31 21:13:35 +03:00
|
|
|
type: InputStatusTypes;
|
2021-01-31 06:33:01 +03:00
|
|
|
icon: any; // Element type of sorts?
|
|
|
|
message: string;
|
2021-02-07 06:38:58 +03:00
|
|
|
}
|
|
|
|
interface InputStates {
|
|
|
|
[key: string]: StatusState;
|
|
|
|
}
|
2021-01-31 06:33:01 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
export const INPUT_STATES: InputStates = {
|
2021-01-31 06:33:01 +03:00
|
|
|
[STATUS_SUCCESS]: {
|
2021-02-01 08:36:14 +03:00
|
|
|
type: STATUS_SUCCESS,
|
2021-01-31 06:33:01 +03:00
|
|
|
icon: <CheckCircleFilled style={{ color: 'green' }} />,
|
|
|
|
message: 'Success!',
|
|
|
|
},
|
|
|
|
[STATUS_ERROR]: {
|
2021-02-01 08:36:14 +03:00
|
|
|
type: STATUS_ERROR,
|
2021-01-31 06:33:01 +03:00
|
|
|
icon: <ExclamationCircleFilled style={{ color: 'red' }} />,
|
2021-01-31 21:13:35 +03:00
|
|
|
message: 'An error occurred.',
|
2021-01-31 06:33:01 +03:00
|
|
|
},
|
|
|
|
[STATUS_INVALID]: {
|
2021-02-01 08:36:14 +03:00
|
|
|
type: STATUS_INVALID,
|
2021-01-31 06:33:01 +03:00
|
|
|
icon: <ExclamationCircleFilled style={{ color: 'red' }} />,
|
2021-01-31 21:13:35 +03:00
|
|
|
message: 'An error occurred.',
|
2021-01-31 06:33:01 +03:00
|
|
|
},
|
|
|
|
[STATUS_PROCESSING]: {
|
2021-02-01 08:36:14 +03:00
|
|
|
type: STATUS_PROCESSING,
|
2021-01-31 06:33:01 +03:00
|
|
|
icon: <LoadingOutlined />,
|
|
|
|
message: '',
|
|
|
|
},
|
|
|
|
[STATUS_WARNING]: {
|
2021-02-01 08:36:14 +03:00
|
|
|
type: STATUS_WARNING,
|
2021-01-31 06:33:01 +03:00
|
|
|
icon: <WarningOutlined style={{ color: '#fc0' }} />,
|
2021-01-31 21:13:35 +03:00
|
|
|
message: '',
|
2021-01-31 06:33:01 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't like any of the default messages in INPUT_STATES? Create a state with custom message by providing an icon style with your message.
|
2021-01-31 11:48:39 +03:00
|
|
|
export function createInputStatus(type: InputStatusTypes, message?: string): StatusState {
|
2021-01-31 06:33:01 +03:00
|
|
|
if (!type || !INPUT_STATES[type]) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-01-31 21:13:35 +03:00
|
|
|
if (!message) {
|
2021-01-31 06:33:01 +03:00
|
|
|
return INPUT_STATES[type];
|
|
|
|
}
|
|
|
|
return {
|
2021-01-31 21:13:35 +03:00
|
|
|
type,
|
2021-01-31 06:33:01 +03:00
|
|
|
icon: INPUT_STATES[type].icon,
|
|
|
|
message,
|
|
|
|
};
|
|
|
|
}
|