import React, { useState } from 'react' import { View, TouchableOpacity, Platform } from 'react-native' import { useLanguage, useSession, useUtils, Sessions as SessionsController } from 'ordering-components/native' import NavBar from '../NavBar' import { SessionsParams } from '../../types' import { OAlert } from '../../../../../src/components/shared' import { OButton, OIcon, OText } from '../shared' import { useTheme } from 'styled-components/native' import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder' import AntIcon from 'react-native-vector-icons/AntDesign' import { SessionsWrapper, SessionItem, DurationWrapper, Container } from './styles' export const SessionsUI = (props: SessionsParams) => { const { navigation, sessionsList, actionState, handleDeleteSession, handleDeleteAllSessions } = props const [, t] = useLanguage() const [{ user }] = useSession() const [{ parseDate }] = useUtils() const theme = useTheme() const [confirm, setConfirm] = useState({ open: false, content: null, handleOnAccept: null, id: null, title: null }) const goToBack = () => navigation?.canGoBack() && navigation.goBack() const onDeleteSession = (session: any) => { setConfirm({ open: true, title: t('WEB_APPNAME', 'Ordering'), content: [t('QUESTION_DELETE_SESSION', 'Are you sure to delete this session?')], handleOnAccept: () => { handleDeleteSession(session) setConfirm({ ...confirm, open: false }) } }) } const onDeleteAllSessions = (isOldUser: any, deleteCurrent: any) => { setConfirm({ open: true, title: t('WEB_APPNAME', 'Ordering'), content: isOldUser ? [t('QUESTION_ENABLE_ALL_SESSIONS', 'Are you sure to enable all sessions?')] : deleteCurrent ? [t('QUESTION_DELETE_ALL_SESSIONS', 'Are you sure that you want to delete all sessions?')] : [t('QUESTION_DELETE_ALL_SESSIONS_EXCEPT_CURRENT', 'Are you sure that you want to delete all sessions except current?')], handleOnAccept: () => { handleDeleteAllSessions(deleteCurrent) setConfirm({ ...confirm, open: false }) } }) } return ( {user?.session_strategy === 'jwt_session' ? ( <> {sessionsList.loading ? ( [...Array(5).keys()].map(i => ( )) ) : ( sessionsList.sessions.length > 0 ? ( {sessionsList.sessions.map((session: any) => ( {parseDate(session.created_at)} {parseDate(session.valid_thru)} {session.current && ( ({t('CURRENT', 'Current')}) )} onDeleteSession(session)} > ))} onDeleteAllSessions(false, true)} style={{ borderRadius: 7.6, marginTop: 30 }} /> onDeleteAllSessions(false, false)} style={{ borderRadius: 7.6, marginTop: 20 }} /> ) : ( {t('YOU_DONT_HAVE_ANY_SESSIONS', 'You don\'t have any sessions')} ) )} ) : ( {t('YOU_DONT_HAVE_ENABLED_THE_SESSIONS', 'You don\'t have enabled the sessions, please active them to have a better control of your sessions.')} onDeleteAllSessions(true, false)} style={{ borderRadius: 7.6, marginTop: 20 }} /> )} setConfirm({ ...confirm, open: false, title: null })} onClose={() => setConfirm({ ...confirm, open: false, title: null })} /> ) } export const Sessions = (props: SessionsParams) => { const sessionsProps = { ...props, UIComponent: SessionsUI } return }