Skip to content
Closed
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
2 changes: 1 addition & 1 deletion expo-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// <reference types="expo/types" />

// NOTE: This file should not be edited and should be in your git ignore
// NOTE: This file should not be edited and should be in your git ignore
26 changes: 20 additions & 6 deletions src/api/common/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,26 @@ axiosInstance.interceptors.response.use(
return axiosInstance(originalRequest);
} catch (refreshError) {
processQueue(refreshError as Error);
// Handle refresh token failure
useAuthStore.getState().logout();
logger.error({
message: 'Token refresh failed',
context: { error: refreshError },
});

// Check if it's a network error vs an invalid refresh token
const isNetworkError =
refreshError instanceof Error &&
(refreshError.message.includes('Network Error') || refreshError.message.includes('timeout') || refreshError.message.includes('ECONNREFUSED') || refreshError.message.includes('ETIMEDOUT'));

if (!isNetworkError) {
// Only logout for non-network errors (e.g., invalid refresh token, 400/401 from token endpoint)
logger.error({
message: 'Token refresh failed with non-recoverable error, logging out user',
context: { error: refreshError },
});
useAuthStore.getState().logout();
} else {
logger.warn({
message: 'Token refresh failed due to network error',
context: { error: refreshError },
});
}

return Promise.reject(refreshError);
} finally {
isRefreshing = false;
Expand Down
10 changes: 5 additions & 5 deletions src/app/(app)/__tests__/protocols.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jest.mock('@/components/protocols/protocol-card', () => ({
ProtocolCard: ({ protocol, onPress }: { protocol: any; onPress: (id: string) => void }) => {
const { Pressable, Text } = require('react-native');
return (
<Pressable testID={`protocol-card-${protocol.Id}`} onPress={() => onPress(protocol.Id)}>
<Pressable testID={`protocol-card-${protocol.ProtocolId}`} onPress={() => onPress(protocol.ProtocolId)}>
<Text>{protocol.Name}</Text>
</Pressable>
);
Expand Down Expand Up @@ -108,7 +108,7 @@ jest.mock('@/stores/protocols/store', () => ({
// Mock protocols test data
const mockProtocols: CallProtocolsResultData[] = [
{
Id: '1',
ProtocolId: '1',
DepartmentId: 'dept1',
Name: 'Fire Emergency Response',
Code: 'FIRE001',
Expand All @@ -126,7 +126,7 @@ const mockProtocols: CallProtocolsResultData[] = [
Questions: [],
},
{
Id: '2',
ProtocolId: '2',
DepartmentId: 'dept1',
Name: 'Medical Emergency',
Code: 'MED001',
Expand All @@ -144,7 +144,7 @@ const mockProtocols: CallProtocolsResultData[] = [
Questions: [],
},
{
Id: '3',
ProtocolId: '3',
DepartmentId: 'dept1',
Name: 'Hazmat Response',
Code: 'HAZ001',
Expand All @@ -162,7 +162,7 @@ const mockProtocols: CallProtocolsResultData[] = [
Questions: [],
},
{
Id: '', // Empty ID to test the keyExtractor fix
ProtocolId: '', // Empty ID to test the keyExtractor fix
DepartmentId: 'dept1',
Name: 'Protocol with Empty ID',
Code: 'EMPTY001',
Expand Down
13 changes: 11 additions & 2 deletions src/app/(app)/protocols.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export default function Protocols() {
setRefreshing(false);
}, [fetchProtocols]);

const handleProtocolPress = React.useCallback(
(id: string) => {
selectProtocol(id);
},
[selectProtocol]
);

const filteredProtocols = React.useMemo(() => {
if (!searchQuery.trim()) return protocols;

Expand Down Expand Up @@ -69,11 +76,13 @@ export default function Protocols() {
<FlatList
testID="protocols-list"
data={filteredProtocols}
keyExtractor={(item, index) => item.Id || `protocol-${index}`}
renderItem={({ item }) => <ProtocolCard protocol={item} onPress={selectProtocol} />}
keyExtractor={(item, index) => item.ProtocolId || `protocol-${index}`}
renderItem={({ item }) => <ProtocolCard protocol={item} onPress={handleProtocolPress} />}
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingBottom: 100 }}
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} />}
extraData={handleProtocolPress}
estimatedItemSize={120}
/>
) : (
<ZeroState icon={FileText} heading={t('protocols.empty')} description={t('protocols.emptyDescription')} />
Expand Down
Loading
Loading