Skip to content

Commit

Permalink
refactor(utils): transform to typescript file
Browse files Browse the repository at this point in the history
  • Loading branch information
Hashs7 committed Nov 6, 2024
1 parent 5ea5ab0 commit c22ff35
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/app/solicitar-ayuda/_components/Form/FormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';

import { FormRenderer } from './FormRenderer';
import { FormData, Status } from '../types';
// @ts-expect-error
import { formatPhoneNumber, isValidPhone } from '@/helpers/utils';
import { helpRequestService } from '@/lib/service';
import { Database } from '@/types/database';
Expand Down
5 changes: 2 additions & 3 deletions src/app/solicitar-ayuda/_components/Form/FormRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import React from 'react';
import { Check } from 'lucide-react';

import { PhoneInput } from '@/components/PhoneInput';
// @ts-expect-error
import AddressAutocomplete from '@/components/AddressAutocomplete';
import AddressAutocomplete from '@/components/AddressAutocomplete.js';
import { TIPOS_DE_AYUDA } from '../constants';
import { TipoDeAyudaInputRenderer } from '../TipoDeAyudaInputRenderer';
import { FormData, HelpCategory, Status, Town } from '../types';
import { FormData, HelpCategory, Status } from '../types';
import { TownSelector } from '../TownSelector';

type FormRendererProps = {
Expand Down
1 change: 0 additions & 1 deletion src/components/PhoneInput/PhoneInputContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { useCallback, useState } from 'react';

import { PhoneInputRenderer } from './PhoneInputRenderer';
import { PhoneInputProps } from './types';
// @ts-expect-error
import { isValidPhone } from '@/helpers/utils';

export function PhoneInputContainer({ onChange, phoneNumber, required = false }: PhoneInputProps) {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/utils.js → src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { callCenterPhoneTrimmed } from '@/constants/phoneNumber';

const isPhoneEqualToCallCenter = (phoneNumber) => {
const isPhoneEqualToCallCenter = (phoneNumber: string) => {
return phoneNumber === callCenterPhoneTrimmed;
};

export const isValidPhone = (phoneNumber) => {
export const isValidPhone = (phoneNumber: string) => {
const phoneNumberWithoutSpaces = phoneNumber.replace(/\D/g, '');

return (
Expand All @@ -14,7 +14,7 @@ export const isValidPhone = (phoneNumber) => {
);
};

export const formatPhoneNumber = (value) => {
export const formatPhoneNumber = (value: string) => {
// Remove white spaces and non-digit characters
return value.replace(/\s/g, '').replace(/\D/g, '');
};

0 comments on commit c22ff35

Please sign in to comment.