Skip to content

Commit

Permalink
chore: lint and remove unnecessary conditions (#183)
Browse files Browse the repository at this point in the history
* chore: lint and remove unnecessary conditions

* chore: fix build
  • Loading branch information
JuroUhlar authored Dec 3, 2024
1 parent 9eba74d commit 5063d00
Show file tree
Hide file tree
Showing 42 changed files with 139 additions and 139 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ module.exports = {
// necessary to pickup project-specific overrides in prettierrc.js
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json', // Adjust the path if necessary
tsconfigRootDir: __dirname,
},
plugins: ['react-hooks', 'jsx-a11y'],
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unnecessary-condition': 'error',
'react/no-unescaped-entities': 'off',
},
};
2 changes: 1 addition & 1 deletion src/app/LayoutUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './LayoutUI.module.scss';

export function LayoutUI({ children }: { children: React.ReactNode }) {
const segments = useSelectedLayoutSegments();
const embed = Boolean(segments?.includes('embed'));
const embed = Boolean(segments.includes('embed'));
return (
<div className={styles.layout}>
{embed ? null : <Header />}
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/admin/reset/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function POST(req: NextRequest): Promise<NextResponse<ResetResponse
return NextResponse.json({ severity: 'error', message: fingerprintResult.error }, { status: 403 });
}

const { visitorId, ip } = fingerprintResult.data.products?.identification?.data ?? {};
const { visitorId, ip } = fingerprintResult.data.products.identification?.data ?? {};
if (!visitorId) {
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 });
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/decrypt/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type DecryptResponse = EventResponse;

export async function POST(request: Request) {
try {
const sealedData = ((await request?.json()) as DecryptPayload).sealedResult;
const sealedData = ((await request.json()) as DecryptPayload).sealedResult;
const data = await decryptSealedResult(sealedData);
return Response.json(data);
} catch (e) {
Expand Down
38 changes: 19 additions & 19 deletions src/app/bot-firewall/BotFirewall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,22 @@ export const BotFirewall: FunctionComponent = () => {
</tr>
</thead>
<tbody>
{botVisits?.slice(0, displayedVisits).map((botVisit) => {
{botVisits.slice(0, displayedVisits).map((botVisit) => {
return (
<tr key={botVisit?.requestId}>
<td>{formatDate(botVisit?.timestamp)}</td>
<td>{botVisit?.requestId}</td>
<tr key={botVisit.requestId}>
<td>{formatDate(botVisit.timestamp)}</td>
<td>{botVisit.requestId}</td>
<td>
{botVisit?.botResult} ({botVisit.botType})
{botVisit.botResult} ({botVisit.botType})
</td>
<td className={styles.wrapAndBreakTableCell}>{botVisit?.ip}</td>
<td className={styles.wrapAndBreakTableCell}>{botVisit.ip}</td>
<td>
<BotVisitAction
ip={botVisit?.ip}
isBlockedNow={isIpBlocked(botVisit?.ip)}
ip={botVisit.ip}
isBlockedNow={isIpBlocked(botVisit.ip)}
blockIp={blockIp}
isLoadingBlockIp={isLoadingBlockIp}
isVisitorsIp={botVisit?.ip === visitorData?.ip}
isVisitorsIp={botVisit.ip === visitorData?.ip}
/>
</td>
</tr>
Expand All @@ -197,32 +197,32 @@ export const BotFirewall: FunctionComponent = () => {

{/* Display bot visits as **CARDS** only on small screens */}
<div className={styles.cards}>
{botVisits?.slice(0, displayedVisits).map((botVisit) => {
{botVisits.slice(0, displayedVisits).map((botVisit) => {
return (
<div key={botVisit.requestId} className={styles.card}>
<div className={styles.cardContent}>
<div>Timestamp</div>
<div>{formatDate(botVisit?.timestamp)}</div>
<div>{formatDate(botVisit.timestamp)}</div>

<div>Request ID</div>
<div>{botVisit?.requestId}</div>
<div>{botVisit.requestId}</div>

<div>
Bot Type <BotTypeInfo />
</div>
<div>
{botVisit?.botResult} ({botVisit.botType})
{botVisit.botResult} ({botVisit.botType})
</div>

<div>IP Address</div>
<div>{botVisit?.ip}</div>
<div>{botVisit.ip}</div>
</div>
<BotVisitAction
ip={botVisit?.ip}
isBlockedNow={isIpBlocked(botVisit?.ip)}
ip={botVisit.ip}
isBlockedNow={isIpBlocked(botVisit.ip)}
blockIp={blockIp}
isLoadingBlockIp={isLoadingBlockIp}
isVisitorsIp={botVisit?.ip === visitorData?.ip}
isVisitorsIp={botVisit.ip === visitorData?.ip}
/>
</div>
);
Expand Down Expand Up @@ -268,13 +268,13 @@ export const BotFirewall: FunctionComponent = () => {

{content}
{/* Display load older bot visits button if necessary */}
{botVisits && botVisits?.length > DEFAULT_DISPLAYED_VISITS ? (
{botVisits && botVisits.length > DEFAULT_DISPLAYED_VISITS ? (
<Button
size='medium'
className={styles.loadMore}
outlined
onClick={() => setDisplayedVisits(displayedVisits + DISPLAYED_VISITS_INCREMENT)}
disabled={!botVisits || displayedVisits >= botVisits.length}
disabled={displayedVisits >= botVisits.length}
>
Show older bot visits
</Button>
Expand Down
12 changes: 6 additions & 6 deletions src/app/bot-firewall/api/get-bot-visits/botVisitDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export const saveBotVisit = async (botData: EventResponseBotData, visitorId: str
BotVisitDbModel.create({
ip: botData.ip,
visitorId: visitorId,
requestId: botData.requestId ?? 'N/A',
timestamp: botData.time ?? 'N/A',
botResult: botData.bot.result ?? 'N/A',
botType: botData.bot.type ?? 'N/A',
userAgent: botData.userAgent ?? 'N/A',
url: botData.url ?? 'N/A',
requestId: botData.requestId,
timestamp: botData.time,
botResult: botData.bot.result,
botType: botData.bot.type ?? '',
userAgent: botData.userAgent,
url: botData.url,
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/coupon-fraud/CouponFraud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function CouponFraudUseCase() {
{isLoading ? 'Processing...' : 'Apply'}
</Button>
</div>
{claimResponse?.message && !isLoading && (
{claimResponse?.message && (
<div>
<Alert severity={claimResponse.severity}>{claimResponse.message}</Alert>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/coupon-fraud/api/claim/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function POST(req: Request): Promise<NextResponse<CouponClaimRespon
}

// Get visitorId from the Server API Identification event
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId;
const visitorId = fingerprintResult.data.products.identification?.data?.visitorId;
if (!visitorId) {
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 });
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/credential-stuffing/CredentialStuffing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function CredentialStuffing() {
<Image src={showPassword ? shownIcon : hiddenIcon} alt={showPassword ? 'Hide password' : 'Show password'} />
</button>
{loginNetworkError && <Alert severity='error'>{loginNetworkError.message}</Alert>}
{loginResponse?.message && !isLoading && (
{loginResponse?.message && (
<Alert severity={loginResponse.severity} className={styles.alert}>
{loginResponse.message}
</Alert>
Expand Down
2 changes: 1 addition & 1 deletion src/app/credential-stuffing/api/authenticate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function POST(req: Request): Promise<NextResponse<LoginResponse>> {
}

// Get visitorId from the Server API Identification event
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId;
const visitorId = fingerprintResult.data.products.identification?.data?.visitorId;
if (!visitorId) {
logLoginAttempt(clientVisitorId, username, 'RequestIdValidationFailed');
return NextResponse.json({ message: 'Visitor ID not found.', severity: 'error' }, { status: 403 });
Expand Down
2 changes: 1 addition & 1 deletion src/app/loan-risk/LoanRisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function LoanRisk() {
</div>
</div>
{loanRequestNetworkError && <Alert severity='error'>{loanRequestNetworkError.message}</Alert>}
{loanRequestResponse?.message && !isLoanRequestLoading && (
{loanRequestResponse?.message && (
<Alert severity={loanRequestResponse.severity}>{loanRequestResponse.message}</Alert>
)}
<Button
Expand Down
2 changes: 1 addition & 1 deletion src/app/loan-risk/api/request-loan/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function POST(req: Request): Promise<NextResponse<LoanRequestRespon
}

// Get visitorId from the Server API Identification event
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId;
const visitorId = fingerprintResult.data.products.identification?.data?.visitorId;
if (!visitorId) {
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 });
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/payment-fraud/api/place-order/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function POST(req: Request): Promise<NextResponse<PaymentResponse>>
}

// Get visitorId from the Server API Identification event
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId;
const visitorId = fingerprintResult.data.products.identification?.data?.visitorId;
if (!visitorId) {
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 });
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/paywall/Paywall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default function Paywall({ embed }: { embed: boolean }) {
const gridArticles = ARTICLES.slice(1);
return (
<UseCaseWrapper useCase={USE_CASES.paywall}>
{heroArticle && <ArticleCard article={heroArticle} isHeroArticle embed={embed} />}
{gridArticles && <ArticleGrid articles={gridArticles} embed={embed} />}
<ArticleCard article={heroArticle} isHeroArticle embed={embed} />
<ArticleGrid articles={gridArticles} embed={embed} />
</UseCaseWrapper>
);
}
2 changes: 1 addition & 1 deletion src/app/paywall/api/article/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function POST(
}

// Get visitorId from the Server API Identification event
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId;
const visitorId = fingerprintResult.data.products.identification?.data?.visitorId;
if (!visitorId) {
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 });
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/personalization/Personalization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function Personalization() {
const { showNotification } = usePersonalizationNotification();

useEffect(() => {
if (productsQuery.data?.data?.querySaved) {
if (productsQuery.data?.data.querySaved) {
showNotification('Search query saved!');
}
}, [productsQuery.data, showNotification]);
Expand All @@ -57,7 +57,7 @@ export function Personalization() {
useEffect(() => {
if (
data?.incognito &&
data?.visitorFound &&
data.visitorFound &&
!userWelcomed &&
(searchHistoryQuery.data?.data?.length || cartQuery.data?.data?.length)
) {
Expand Down Expand Up @@ -118,7 +118,7 @@ export function Personalization() {
<Spinner size={36} className={styles.spinner} />
) : (
<>
{productsQuery.data?.data?.products?.length ? (
{productsQuery.data?.data.products.length ? (
productsQuery.data.data.products.map((product) => (
<ProductCard key={product.id} product={product} />
))
Expand Down
6 changes: 3 additions & 3 deletions src/app/personalization/api/cart/add-item/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function POST(req: NextRequest): Promise<NextResponse<AddCartItemRe
}

// Get visitorId from the Server API Identification event
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId;
const visitorId = fingerprintResult.data.products.identification?.data?.visitorId;
if (!visitorId) {
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 });
}
Expand All @@ -48,14 +48,14 @@ export async function POST(req: NextRequest): Promise<NextResponse<AddCartItemRe
const [cartItem, created] = await UserCartItemDbModel.findOrCreate({
where: {
visitorId: {
[Op.eq]: visitorId ?? '',
[Op.eq]: visitorId,
},
productId: {
[Op.eq]: productId,
},
},
defaults: {
visitorId: visitorId ?? '',
visitorId: visitorId,
count: 1,
timestamp: new Date(),
productId,
Expand Down
2 changes: 1 addition & 1 deletion src/app/personalization/api/get-search-history/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function POST(req: NextRequest): Promise<NextResponse<SearchHistory
}

// Get visitorId from the Server API Identification event
const visitorId = fingerprintResult.data.products?.identification?.data?.visitorId;
const visitorId = fingerprintResult.data.products.identification?.data?.visitorId;
if (!visitorId) {
return NextResponse.json({ severity: 'error', message: 'Visitor ID not found.' }, { status: 403 });
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/personalization/components/productCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const ProductCard: FunctionComponent<{ product: Product }> = ({ product }

const removeFromCart = async () => {
if (cartItem) {
await removeCartItemMutation.mutateAsync({ itemId: cartItem?.id });
await removeCartItemMutation.mutateAsync({ itemId: cartItem.id });
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/personalization/components/searchComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type SearchHistoryProps = {
};

export const SearchHistory: FunctionComponent<SearchHistoryProps> = ({ searchHistory, setSearchHistory }) => {
if (!searchHistory || searchHistory?.length === 0) {
if (!searchHistory || searchHistory.length === 0) {
return null;
}

Expand Down
13 changes: 4 additions & 9 deletions src/app/personalization/hooks/use-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ export function useCart() {
enabled: Boolean(visitorData),
});

const refetchCartOnSuccess = useCallback(
async (data: AddCartItemResponse | RemoveCartItemResponse) => {
if (data) {
await cartQuery.refetch();
}
},
[cartQuery],
);
const refetchCartOnSuccess = useCallback(async () => {
await cartQuery.refetch();
}, [cartQuery]);

const addCartItemMutation = useMutation({
mutationKey: [ADD_CART_ITEM_MUTATION],
Expand All @@ -56,7 +51,7 @@ export function useCart() {
});
return (await response.json()) as AddCartItemResponse;
},
onSuccess: (data: AddCartItemResponse) => refetchCartOnSuccess(data),
onSuccess: () => refetchCartOnSuccess(),
});

const removeCartItemMutation = useMutation({
Expand Down
Loading

0 comments on commit 5063d00

Please sign in to comment.