File size: 977 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { FoldableCard, Spinner } from '@automattic/components';
import { Icon } from '@wordpress/components';
import { check, closeSmall } from '@wordpress/icons';
import clsx from 'clsx';
import { ReactNode } from 'react';
import { WorkFlowStates } from './use-check-workflow-query';

export const WorkflowValidation = ( {
	status,
	label,
	children,
}: {
	status: WorkFlowStates;
	label: string;
	children: ReactNode;
} ) => {
	const getValidationIcon = () => {
		if ( status === 'loading' ) {
			return <Spinner className="custom-icons" />;
		}

		return (
			<Icon
				size={ 20 }
				icon={ status === 'success' ? check : closeSmall }
				className={ clsx( 'custom-icons', status ) }
			/>
		);
	};

	return (
		<div>
			<FoldableCard
				className={ status === 'error' ? 'is-error' : '' }
				clickableHeader
				expanded={ false }
				header={
					<>
						{ getValidationIcon() }
						{ label }
					</>
				}
			>
				{ children }
			</FoldableCard>
		</div>
	);
};