Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
46efa425
Commit
46efa425
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
GREG-60: Fixing comment from code review
parent
144a3264
No related branches found
No related tags found
1 merge request
!81
GREG-60: Mobile phone validation
Pipeline
#95832
passed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/utils/index.ts
+44
-45
44 additions, 45 deletions
frontend/src/utils/index.ts
with
44 additions
and
45 deletions
frontend/src/utils/index.ts
+
44
−
45
View file @
46efa425
import
validator
from
'
@navikt/fnrvalidator
'
import
i18n
from
'
i18next
'
import
{
isValidPhoneNumber
}
from
'
libphonenumber-js
'
import
{
isValidPhoneNumber
}
from
'
libphonenumber-js
'
export
function
getCookie
(
name
:
string
)
{
if
(
!
document
.
cookie
)
{
return
null
}
if
(
!
document
.
cookie
)
{
return
null
}
const
cookies
=
document
.
cookie
.
split
(
'
;
'
)
.
map
((
c
)
=>
c
.
trim
())
.
filter
((
c
)
=>
c
.
startsWith
(
`
${
name
}
=`
))
const
cookies
=
document
.
cookie
.
split
(
'
;
'
)
.
map
((
c
)
=>
c
.
trim
())
.
filter
((
c
)
=>
c
.
startsWith
(
`
${
name
}
=`
))
if
(
cookies
.
length
===
0
)
{
return
null
}
return
decodeURIComponent
(
cookies
[
0
].
split
(
'
=
'
)[
1
])
if
(
cookies
.
length
===
0
)
{
return
null
}
return
decodeURIComponent
(
cookies
[
0
].
split
(
'
=
'
)[
1
])
}
export
function
maybeCsrfToken
()
{
const
csrfToken
=
getCookie
(
'
csrftoken
'
)
if
(
!
csrfToken
)
{
return
null
}
return
{
'
X-CSRFToken
'
:
csrfToken
,
}
const
csrfToken
=
getCookie
(
'
csrftoken
'
)
if
(
!
csrfToken
)
{
return
null
}
return
{
'
X-CSRFToken
'
:
csrfToken
,
}
}
export
function
postJsonOpts
(
data
:
object
):
RequestInit
{
return
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
...
maybeCsrfToken
(),
},
body
:
JSON
.
stringify
(
data
),
credentials
:
'
same-origin
'
,
}
return
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
...
maybeCsrfToken
(),
},
body
:
JSON
.
stringify
(
data
),
credentials
:
'
same-origin
'
,
}
}
export
function
isValidFnr
(
data
:
string
|
undefined
):
boolean
|
string
{
if
(
data
===
null
)
{
if
(
data
===
null
)
{
return
i18n
.
t
(
'
common:validation.invalidIdNumber
'
).
toString
()
}
const
valid
=
validator
.
idnr
(
data
as
string
).
status
===
'
valid
'
if
(
valid
)
{
return
true
}
// TypeScript complains if toString is not used on the function result
return
i18n
.
t
(
'
common:validation.invalidIdNumber
'
).
toString
()
}
const
valid
=
validator
.
idnr
(
data
as
string
).
status
===
'
valid
'
if
(
valid
)
{
return
true
}
// TypeScript complains if toString is not used on the function result
return
i18n
.
t
(
'
common:validation.invalidIdNumber
'
).
toString
()
}
export
function
isValidMobilePhoneNumber
(
data
:
string
|
undefined
):
boolean
|
string
{
if
(
!
data
)
{
return
i18n
.
t
(
'
common:validation.invalidMobilePhoneNumber
'
).
toString
()
}
const
valid
=
isValidPhoneNumber
(
data
)
if
(
valid
)
{
return
true
}
// TypeScript complains if toString is not used on the function result
return
i18n
.
t
(
'
common:validation.invalidMobilePhoneNumber
'
).
toString
()
if
(
!
data
)
{
return
i18n
.
t
<
string
>
(
'
common:validation.invalidMobilePhoneNumber
'
)
}
const
valid
=
isValidPhoneNumber
(
data
)
if
(
valid
)
{
return
true
}
return
i18n
.
t
<
string
>
(
'
common:validation.invalidMobilePhoneNumber
'
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment