Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] Local storage handling #252

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import Image from 'next/image'
import { Color } from '../../../types/elements'
import { Cam } from '../Cam/Cam'
Expand Down Expand Up @@ -45,6 +45,12 @@ export const FaceEnrollment = ({ openModal, payload, nextStep }: Props) => {
}
]

useEffect(() => {
if (localStorage.getItem(ENROLL_SNAPSHOT)) {
localStorage.removeItem(ENROLL_SNAPSHOT)
}
}, [])
Comment on lines +48 to +52
Copy link
Collaborator

@gregoriusjimmy gregoriusjimmy Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gw enroll face berhasil terus gw refresh, coba lagi, masih kesimpen foto sebelumnya tapi gabisa next. local storage disini bukannya emg tujuanya biar user ga perlu foto lagi kalo ke refresh/keluar halaman?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, jim. Kadang kalo solution nya tengah jalan ditinggalin user, string base64 nya tetep disimpen di localStorage. Takut user nya kaget aja pas buka lagi abis udah lama ga buka.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Berarti di useEffectnya mesti ada condition buat ngecheck kalau session_idnya masih ada atau engga, kalau engga adaa berarti baru kita apus di local storagenya, kayak gitu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boleh kalo pengen nambah cek session_id jim


const getPhoto = () => {
const photo = localStorage.getItem(ENROLL_SNAPSHOT)
if (session_id && photo) {
Expand Down
8 changes: 8 additions & 0 deletions frontend/app/components/modules/PaymentPay/PaymentPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ export const PaymentPay = ({
paymentAccountInfo.minimum_payment
])

// To ensure localStorage stays empty
// when user refresh the page
useEffect(() => {
if (localStorage.getItem(FACE_MATCH_LIVENESS_SNAPSHOT)) {
localStorage.removeItem(FACE_MATCH_LIVENESS_SNAPSHOT)
}
}, [])

const checkPhone = () => {
if (paymentAccountInfo.phone !== phone) {
setPhoneError('Your phone number does not match with the registered one')
Expand Down
13 changes: 12 additions & 1 deletion frontend/app/components/templates/EkycPage/EkycPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseCookies } from 'nookies'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { postActivities } from '../../../api/activitiesAPI'
import { Color } from '../../../types/elements'
import { Button } from '../../elements/Button/Button'
Expand Down Expand Up @@ -34,6 +34,17 @@ export const EkycPage = ({ serviceId, name, longDesc }: Props) => {
const [result, setResult] = useState<EKYCResultResponse>()
const [loading, setLoading] = useState(true)

// To ensure localStorage stays empty
// when user refresh the page
useEffect(() => {
if (localStorage.getItem(FL_LOCAL_STORAGE)) {
localStorage.removeItem(FL_LOCAL_STORAGE)
}
if (localStorage.getItem(KTP_LOCAL_STORAGE)) {
localStorage.removeItem(KTP_LOCAL_STORAGE)
}
}, [])

const createVisitorActivities = async (
serviceId: number,
sessionId: string,
Expand Down