Skip to content

Commit

Permalink
chore(prettier): lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKunalGupta committed Mar 11, 2024
1 parent c14cde3 commit 471eea7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 23 deletions.
20 changes: 13 additions & 7 deletions ui/app/alert-config/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import SelectTheme from '../styles/select';
import {
alertConfigReqSchema,
alertConfigType,
emailConfigType, serviceConfigType,
emailConfigType,
serviceConfigType,
serviceTypeSchemaMap,
slackConfigType
slackConfigType,
} from './validation';

export type ServiceType = 'slack' | 'email';
Expand Down Expand Up @@ -151,14 +152,19 @@ export function NewConfig(alertProps: AlertConfigProps) {
return;
}

const serviceSchema = serviceTypeSchemaMap[serviceType]
const serviceValidity = serviceSchema.safeParse(config)
if(!serviceValidity?.success){
notifyErr("Invalid alert service configuration for "+ serviceType + ". " + serviceValidity.error.issues[0].message)
const serviceSchema = serviceTypeSchemaMap[serviceType];
const serviceValidity = serviceSchema.safeParse(config);
if (!serviceValidity?.success) {
notifyErr(
'Invalid alert service configuration for ' +
serviceType +
'. ' +
serviceValidity.error.issues[0].message
);
return;
}

const serviceConfig = serviceValidity.data
const serviceConfig = serviceValidity.data;
const alertConfigReq: alertConfigType = {
id: Number(alertProps.id || -1),
serviceType: serviceType,
Expand Down
49 changes: 40 additions & 9 deletions ui/app/alert-config/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ import { tableStyle } from '../peers/[peerName]/style';
import { fetcher } from '../utils/swr';
import { AlertConfigProps, NewConfig, ServiceType } from './new';

const ServiceIcon = ({serviceType, size}: {serviceType:string, size:number}) => {
return <Image src={`/images/${serviceType}.png`} height={size} width={size} alt={serviceType} />;
const ServiceIcon = ({
serviceType,
size,
}: {
serviceType: string;
size: number;
}) => {
return (
<Image
src={`/images/${serviceType}.png`}
height={size}
width={size}
alt={serviceType}
/>
);
};

const AlertConfigPage: React.FC = () => {
Expand Down Expand Up @@ -79,13 +92,31 @@ const AlertConfigPage: React.FC = () => {
{alerts?.length ? (
alerts.map((alertConfig: UAlertConfigResponse, index) => (
<TableRow key={index}>
<TableCell style={{ width:20 }}>
<div style={{display:'flex', flexDirection:'column', alignItems:'center', justifyContent:'center'}}>
<div style={{display:'flex', alignItems:'center', columnGap:'0.5rem'}}>
<ServiceIcon serviceType={alertConfig.service_type} size={30}/>
<Label>{alertConfig.service_type.charAt(0).toUpperCase() + alertConfig.service_type.slice(1)}</Label>
</div>

<TableCell style={{ width: 20 }}>
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
}}
>
<div
style={{
display: 'flex',
alignItems: 'center',
columnGap: '0.5rem',
}}
>
<ServiceIcon
serviceType={alertConfig.service_type}
size={30}
/>
<Label>
{alertConfig.service_type.charAt(0).toUpperCase() +
alertConfig.service_type.slice(1)}
</Label>
</div>
</div>
</TableCell>
<TableCell>
Expand Down
18 changes: 11 additions & 7 deletions ui/app/alert-config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export const slackServiceConfigSchema = z.intersection(
.min(1, { message: 'Auth Token cannot be empty' })
.max(256, { message: 'Auth Token is too long' }),
channel_ids: z
.array(z.string().trim().min(1, { message: 'Channel IDs cannot be empty' }), {
required_error: 'We need a channel ID',
})
.array(
z.string().trim().min(1, { message: 'Channel IDs cannot be empty' }),
{
required_error: 'We need a channel ID',
}
)
.min(1, { message: 'Atleast one channel ID is needed' }),
})
);
Expand All @@ -35,7 +38,8 @@ export const emailServiceConfigSchema = z.intersection(
email_addresses: z
.array(
z
.string().trim()
.string()
.trim()
.min(1, { message: 'Email Addresses cannot be empty' })
.includes('@'),
{
Expand Down Expand Up @@ -68,6 +72,6 @@ export type serviceConfigType = z.infer<typeof serviceConfigSchema>;
export type alertConfigType = z.infer<typeof alertConfigReqSchema>;

export const serviceTypeSchemaMap = {
'slack':slackServiceConfigSchema,
'email':emailServiceConfigSchema
}
slack: slackServiceConfigSchema,
email: emailServiceConfigSchema,
};

0 comments on commit 471eea7

Please sign in to comment.