From 1dee84f400a406e6ea8a72a067e22b9e50cc82b8 Mon Sep 17 00:00:00 2001 From: habib-deriv Date: Sun, 4 Feb 2024 20:09:47 +0800 Subject: [PATCH] chore: add trim for state --- src/features/hooks/use-states-list/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/features/hooks/use-states-list/index.tsx b/src/features/hooks/use-states-list/index.tsx index 4e51087e79a..3b4ea4bb7f8 100644 --- a/src/features/hooks/use-states-list/index.tsx +++ b/src/features/hooks/use-states-list/index.tsx @@ -6,18 +6,22 @@ export type ResidenceType = { value: string } +const isAlphanumeric = (str: string): boolean => /^[a-zA-Z0-9]+$/.test(str) + const formatStatesList = (states) => { if (!states.length) { return [] } - return states?.map( - ({ text }) => - typeof text !== undefined && { + return states.reduce((acc, { text }) => { + if (text && isAlphanumeric(text)) { + acc.push({ name: text, display_name: text, - }, - ) + }) + } + return acc + }, []) } export const useStatesList = (country_code) => {