Skip to content

Commit a9771b4

Browse files
committed
refactor: Format files according to prettier standards
1 parent 005905d commit a9771b4

25 files changed

+1095
-1044
lines changed

Diff for: src/admin/components/Customization.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export default function Customisation() {
3434

3535
useEffect(() => {
3636
if (isSuccess && data) {
37-
3837
setAppearance(data.customisation.appearence);
3938
setThemes(data.customisation.theme);
4039
setSubmittedAppearance(JSON.parse(data.customisation.appearence));
@@ -66,7 +65,7 @@ export default function Customisation() {
6665
onError: () => {
6766
setErrors({ appearance: 'Invalid JSON format' });
6867
},
69-
}
68+
},
7069
);
7170
} catch (e) {
7271
toast.error('Error', {
@@ -84,7 +83,6 @@ export default function Customisation() {
8483
);
8584
}
8685

87-
8886
return (
8987
<>
9088
<Container>

Diff for: src/admin/components/HyperSwitchForm.tsx

+74-78
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"use client";
1+
'use client';
22

3-
import { useEffect } from "react";
4-
import { useQueryClient } from "@tanstack/react-query";
3+
import { useEffect } from 'react';
4+
import { useQueryClient } from '@tanstack/react-query';
55
import {
66
Container,
77
Input,
@@ -12,111 +12,109 @@ import {
1212
Textarea,
1313
Text,
1414
toast,
15-
} from "@medusajs/ui";
16-
import { Spinner } from "@medusajs/icons";
17-
18-
import { useCredentials } from "../hooks/useCredentials";
19-
import { useCreateCredentials } from "../hooks/useCreateCredentials";
20-
import { validateForm, extractFormData } from "../utils";
21-
import { useHyperswitchForm } from "../hooks/useHyperswitchForm";
22-
15+
} from '@medusajs/ui';
16+
import { Spinner } from '@medusajs/icons';
2317

18+
import { useCredentials } from '../hooks/useCredentials';
19+
import { useCreateCredentials } from '../hooks/useCreateCredentials';
20+
import { validateForm, extractFormData } from '../utils';
21+
import { useHyperswitchForm } from '../hooks/useHyperswitchForm';
2422

2523
const FormField = ({ label, error, children }) => (
26-
<Container className="col-span-5">
24+
<Container className='col-span-5'>
2725
<Label id={label}>{label}</Label>
2826
{children}
29-
{error && <Text className="text-red-500 text-sm mt-1">{error}</Text>}
27+
{error && <Text className='text-red-500 text-sm mt-1'>{error}</Text>}
3028
</Container>
3129
);
3230

3331
const EnvironmentSelect = ({ isEditing, value, onChange, error }) => (
34-
<Container className="col-span-2">
35-
<Label id="environment">Environment</Label>
32+
<Container className='col-span-2'>
33+
<Label id='environment'>Environment</Label>
3634
<Select
3735
disabled={!isEditing}
38-
name="environment"
36+
name='environment'
3937
value={value}
4038
onValueChange={onChange}
4139
>
4240
<Select.Trigger>
43-
<Select.Value placeholder="Select Environment" />
41+
<Select.Value placeholder='Select Environment' />
4442
</Select.Trigger>
4543
<Select.Content>
46-
<Select.Item value="sandbox">Sandbox</Select.Item>
47-
<Select.Item value="production">Production</Select.Item>
44+
<Select.Item value='sandbox'>Sandbox</Select.Item>
45+
<Select.Item value='production'>Production</Select.Item>
4846
</Select.Content>
4947
</Select>
50-
{error && <Text className="text-red-500 text-sm mt-1">{error}</Text>}
48+
{error && <Text className='text-red-500 text-sm mt-1'>{error}</Text>}
5149
</Container>
5250
);
5351

5452
const CaptureMethodSelect = ({ isEditing, value, onChange, error }) => (
55-
<Container className="col-span-2">
56-
<Label id="capture-method">Capture Method</Label>
53+
<Container className='col-span-2'>
54+
<Label id='capture-method'>Capture Method</Label>
5755
<Select
5856
disabled={!isEditing}
59-
name="capture-method"
57+
name='capture-method'
6058
value={value}
6159
onValueChange={onChange}
6260
>
6361
<Select.Trigger>
64-
<Select.Value placeholder="Select Capture Method" />
62+
<Select.Value placeholder='Select Capture Method' />
6563
</Select.Trigger>
6664
<Select.Content>
67-
<Select.Item value="manual">Manual</Select.Item>
68-
<Select.Item value="automatic">Automatic</Select.Item>
65+
<Select.Item value='manual'>Manual</Select.Item>
66+
<Select.Item value='automatic'>Automatic</Select.Item>
6967
</Select.Content>
7068
</Select>
71-
{error && <Text className="text-red-500 text-sm mt-1">{error}</Text>}
69+
{error && <Text className='text-red-500 text-sm mt-1'>{error}</Text>}
7270
</Container>
7371
);
7472

7573
const FormContent = ({ formState, handleChange, isEditing, errors }) => (
7674
<>
77-
<FormField label="API Key" error={errors.publishable_key}>
75+
<FormField label='API Key' error={errors.publishable_key}>
7876
<Input
79-
placeholder="Enter your API Key"
80-
id="publishable-key"
81-
name="publishable-key"
77+
placeholder='Enter your API Key'
78+
id='publishable-key'
79+
name='publishable-key'
8280
onChange={handleChange.publishableKey}
8381
disabled={!isEditing}
8482
value={formState.publishable_key}
8583
/>
8684
</FormField>
8785

88-
<FormField label="API Secret" error={errors.secret_key}>
86+
<FormField label='API Secret' error={errors.secret_key}>
8987
<Input
90-
placeholder="Enter your API Secret"
91-
type="password"
92-
id="secret-key"
93-
name="api-secret-key"
88+
placeholder='Enter your API Secret'
89+
type='password'
90+
id='secret-key'
91+
name='api-secret-key'
9492
onChange={handleChange.secretKey}
9593
disabled={!isEditing}
9694
value={formState.secret_key}
9795
/>
9896
</FormField>
9997

10098
<FormField
101-
label="Payment Response Hash Key"
99+
label='Payment Response Hash Key'
102100
error={errors.payment_hash_key}
103101
>
104102
<Input
105-
placeholder="Enter your Payment Response Hash Key"
106-
type="password"
107-
id="payment-hash-key"
108-
name="payment-response-hash-key"
103+
placeholder='Enter your Payment Response Hash Key'
104+
type='password'
105+
id='payment-hash-key'
106+
name='payment-response-hash-key'
109107
onChange={handleChange.paymentHashKey}
110108
disabled={!isEditing}
111109
value={formState.payment_hash_key}
112110
/>
113111
</FormField>
114112

115-
<FormField label="Webhook URL" error={errors.webhook_url}>
113+
<FormField label='Webhook URL' error={errors.webhook_url}>
116114
<Input
117-
placeholder="Enter your Webhook URL"
118-
id="webhook-url"
119-
name="webhook-url"
115+
placeholder='Enter your Webhook URL'
116+
id='webhook-url'
117+
name='webhook-url'
120118
onChange={handleChange.webhookURL}
121119
disabled={!isEditing}
122120
value={formState.webhook_url}
@@ -137,21 +135,21 @@ const FormContent = ({ formState, handleChange, isEditing, errors }) => (
137135
error={errors.capture_method}
138136
/>
139137

140-
<Container className="col-span-1 flex items-center gap-x-2">
141-
<Label id="enable">Save Cards</Label>
138+
<Container className='col-span-1 flex items-center gap-x-2'>
139+
<Label id='enable'>Save Cards</Label>
142140
<Switch
143141
disabled={!isEditing}
144-
name="enable-save-cards"
142+
name='enable-save-cards'
145143
checked={formState.enable_save_cards}
146144
onCheckedChange={handleChange.enableSaveCards}
147145
/>
148146
</Container>
149147

150-
<FormField label="Appearance" error={errors.appearence}>
148+
<FormField label='Appearance' error={errors.appearence}>
151149
<Textarea
152-
placeholder="Customise Hyperswitch appearance"
153-
id="appearence"
154-
name="appearence"
150+
placeholder='Customise Hyperswitch appearance'
151+
id='appearence'
152+
name='appearence'
155153
onChange={handleChange.appearence}
156154
disabled={!isEditing}
157155
value={formState.appearence}
@@ -160,8 +158,7 @@ const FormContent = ({ formState, handleChange, isEditing, errors }) => (
160158
</>
161159
);
162160

163-
164-
const HyperswitchForm = () => {
161+
const HyperswitchForm = () => {
165162
const queryClient = useQueryClient();
166163
const {
167164
formState,
@@ -179,20 +176,18 @@ const FormContent = ({ formState, handleChange, isEditing, errors }) => (
179176

180177
useEffect(() => {
181178
if (isSuccess && data?.credentials) {
182-
183179
Object.entries(data.credentials).forEach(([key, value]) => {
184-
const setter =
185-
formSetters[(`set${key}`)];
180+
const setter = formSetters[`set${key}`];
186181
if (setter) {
187-
setter(value || "");
182+
setter(value || '');
188183
}
189184
});
190185
}
191186
}, [isSuccess, data]);
192187

193188
const handleEdit = () => setIsEditing(!isEditing);
194189

195-
const handleSubmit = async (event) => {
190+
const handleSubmit = async event => {
196191
event.preventDefault();
197192

198193
if (!isEditing) {
@@ -206,49 +201,50 @@ const FormContent = ({ formState, handleChange, isEditing, errors }) => (
206201

207202
try {
208203
const formData = extractFormData(event.target);
209-
createCredentials(formData,{
204+
createCredentials(formData, {
210205
onSuccess: () => {
211-
queryClient.invalidateQueries({queryKey:["credentials"]});
212-
setErrors({});
213-
handleEdit();
214-
toast.success("Success", {
215-
description: "Settings saved successfully",
216-
});
217-
}});
206+
queryClient.invalidateQueries({ queryKey: ['credentials'] });
207+
setErrors({});
208+
handleEdit();
209+
toast.success('Success', {
210+
description: 'Settings saved successfully',
211+
});
212+
},
213+
});
218214

219215
setErrors({});
220216
} catch (error) {
221-
toast.error("Error", {
222-
description: "Failed to save settings",
217+
toast.error('Error', {
218+
description: 'Failed to save settings',
223219
});
224220
}
225221
};
226222

227223
if (isLoadingData) {
228224
return (
229-
<Container className="flex justify-center items-center h-64">
230-
<Spinner className="animate-spin" />
225+
<Container className='flex justify-center items-center h-64'>
226+
<Spinner className='animate-spin' />
231227
</Container>
232228
);
233229
}
234230

235231
return (
236-
<form className="grid grid-cols-5 gap-3 mt-6" onSubmit={handleSubmit}>
232+
<form className='grid grid-cols-5 gap-3 mt-6' onSubmit={handleSubmit}>
237233
<FormContent
238234
formState={formState}
239235
handleChange={handleChange}
240236
isEditing={isEditing}
241237
errors={errors}
242238
/>
243239

244-
<div className="col-span-2">
245-
<Button variant="primary" disabled={isSubmitting}>
246-
{isEditing ? (isSubmitting ? "Saving..." : "Save Changes") : "Edit"}
240+
<div className='col-span-2'>
241+
<Button variant='primary' disabled={isSubmitting}>
242+
{isEditing ? (isSubmitting ? 'Saving...' : 'Save Changes') : 'Edit'}
247243
</Button>
248244
{isEditing && (
249245
<Button
250-
variant="secondary"
251-
type="reset"
246+
variant='secondary'
247+
type='reset'
252248
onClick={handleEdit}
253249
disabled={isSubmitting}
254250
>
@@ -260,4 +256,4 @@ const FormContent = ({ formState, handleChange, isEditing, errors }) => (
260256
);
261257
};
262258

263-
export default HyperswitchForm;
259+
export default HyperswitchForm;

Diff for: src/admin/components/HyperswitchAppearenceTest.tsx

+17-11
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ interface Appearance {
1010
}
1111

1212
interface ButtonProps {
13-
cart: Omit<Cart, 'refundable_amount' | 'refunded_total'>;
14-
notReady: boolean;
13+
'cart': Omit<Cart, 'refundable_amount' | 'refunded_total'>;
14+
'notReady': boolean;
1515
'data-testid'?: string;
16-
theme?: any;
17-
styles?: any;}
16+
'theme'?: any;
17+
'styles'?: any;
18+
}
1819

1920
const HyperswitchPaymentButton: React.FC<ButtonProps> = ({
2021
cart,
2122
notReady,
2223
'data-testid': dataTestId,
2324
theme,
24-
styles = {
25-
layout: "accordion",
26-
}
25+
styles = {
26+
layout: 'accordion',
27+
},
2728
}) => {
2829
const [hyper, setHyper] = useState<any>();
2930
const [widgets, setWidgets] = useState<any>();
@@ -36,7 +37,9 @@ const HyperswitchPaymentButton: React.FC<ButtonProps> = ({
3637

3738
const loadHyper = async () => {
3839
// @ts-ignore
39-
const hyperInstance = Hyper("pay_G7923fNwwYPA9cYkdAga_secret_i2A2az4IXanuC9syFFW9");
40+
const hyperInstance = Hyper(
41+
'pay_G7923fNwwYPA9cYkdAga_secret_i2A2az4IXanuC9syFFW9',
42+
);
4043
setHyper(hyperInstance);
4144

4245
const appearance = { theme }; // Add the appearance property
@@ -50,10 +53,13 @@ const HyperswitchPaymentButton: React.FC<ButtonProps> = ({
5053
wallets: {
5154
walletReturnUrl: 'https://example.com/complete',
5255
},
53-
...styles
56+
...styles,
5457
};
5558

56-
const unifiedCheckout = widgetsInstance.create('payment', unifiedCheckoutOptions);
59+
const unifiedCheckout = widgetsInstance.create(
60+
'payment',
61+
unifiedCheckoutOptions,
62+
);
5763
checkoutComponent.current = unifiedCheckout;
5864
unifiedCheckout.mount('#unified-checkout');
5965
};
@@ -64,7 +70,7 @@ const HyperswitchPaymentButton: React.FC<ButtonProps> = ({
6470
return () => {
6571
document.body.removeChild(scriptTag);
6672
};
67-
}, [theme,styles]);
73+
}, [theme, styles]);
6874

6975
const handlePayment = useCallback(async () => {
7076
if (!hyper || !widgets) return;

0 commit comments

Comments
 (0)