-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from COS301-SE-2024/fix/mobile/login-flow
Fix/mobile/login flow
- Loading branch information
Showing
6 changed files
with
97 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,15 @@ import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-nat | |
// import { number } from 'zod'; | ||
|
||
const getRandomNumber = () => { | ||
return Math.floor(Math.random() * 20)+300; | ||
return Math.floor(Math.random() * 20) + 300; | ||
}; | ||
|
||
const Dashboard = () => { | ||
const colorScheme = useColorScheme(); | ||
const [numbers, setNumbers] = useState(Array.from({ length: 15 }, getRandomNumber)); | ||
const [isDarkMode, setIsDarkMode] = useState(colorScheme === 'dark'); | ||
const [checkedIn, setCheckedIn] = useState(false); | ||
const [name, setName] = useState("User"); | ||
const toast = useToast() | ||
useEffect(() => { | ||
const intervalId = setInterval(() => { | ||
|
@@ -38,50 +39,22 @@ const Dashboard = () => { | |
return newNumbers; | ||
}); | ||
}, 3000); | ||
// console.log(numbers); | ||
setIsDarkMode(colorScheme === 'dark'); | ||
return () => clearInterval(intervalId); | ||
}, [colorScheme]); | ||
|
||
useEffect(() => { | ||
const getUserDetails = async () => { | ||
console.log("heree"); | ||
try { | ||
const response = await fetch('https://dev.occupi.tech/api/[email protected]') | ||
const data = await response.json(); | ||
if (response.ok) { | ||
saveUserData(JSON.stringify(data)); | ||
console.log(data); | ||
} else { | ||
console.log(data); | ||
toast.show({ | ||
placement: 'top', | ||
render: ({ id }) => { | ||
return ( | ||
<Toast nativeID={id} variant="accent" action="error"> | ||
<ToastTitle>{data.error.message}</ToastTitle> | ||
</Toast> | ||
); | ||
}, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error('Error:', error); | ||
toast.show({ | ||
placement: 'top', | ||
render: ({ id }) => { | ||
return ( | ||
<Toast nativeID={id} variant="accent" action="error"> | ||
<ToastTitle>Network Error: {error.message}</ToastTitle> | ||
</Toast> | ||
); | ||
}, | ||
}); | ||
let result = await SecureStore.getItemAsync('UserData'); | ||
console.log(result); | ||
if (result !== undefined) { | ||
let jsonresult = JSON.parse(result); | ||
setName(String(jsonresult?.data?.details?.name)); | ||
} | ||
}; | ||
getUserDetails(); | ||
}, [toast]); | ||
}, []); | ||
|
||
const checkIn = () => { | ||
if (checkedIn === false) { | ||
setCheckedIn(true); | ||
|
@@ -109,9 +82,7 @@ const Dashboard = () => { | |
async function saveUserEmail(value) { | ||
await SecureStore.setItemAsync('email', value); | ||
} | ||
async function saveUserData(value) { | ||
await SecureStore.setItemAsync('UserData', value); | ||
} | ||
|
||
|
||
saveUserEmail('[email protected]'); | ||
|
||
|
@@ -126,7 +97,7 @@ const Dashboard = () => { | |
<View flexDirection="row" justifyContent="space-between"> | ||
<View> | ||
<Text fontSize={wp('5%')} fontWeight="light" color={textColor}> | ||
Hi Sabrina 👋 | ||
Hi {name} 👋 | ||
</Text> | ||
<Text mt="$4" fontSize={wp('6%')} fontWeight="bold" color={textColor}> | ||
Welcome to Occupi | ||
|
@@ -144,7 +115,7 @@ const Dashboard = () => { | |
<Card flexDirection="row" justifyContent="center" alignItems="center" variant="elevated" mt="$4" style={{ width: wp('43%'), height: hp('12%') }} backgroundColor={cardBackgroundColor} borderRadius={10} > | ||
<Text color={textColor} fontSize={40}>{numbers[0]}</Text> | ||
<View flexDirection="column"> | ||
<View flexDirection="row" alignItems="center"><FontAwesome6 name="arrow-trend-up" size={24} color="yellowgreen" /><Text color="yellowgreen"> {numbers[0]/10+5}%</Text></View> | ||
<View flexDirection="row" alignItems="center"><FontAwesome6 name="arrow-trend-up" size={24} color="yellowgreen" /><Text color="yellowgreen"> {numbers[0] / 10 + 5}%</Text></View> | ||
</View> | ||
</Card> | ||
<Card size="lg" variant="elevated" mt="$4" style={{ width: wp('43%'), height: hp('12%') }} backgroundColor={cardBackgroundColor} borderRadius={10} /> | ||
|
@@ -169,10 +140,10 @@ const Dashboard = () => { | |
<View> | ||
<Text color={textColor}>Occupancy levels</Text> | ||
<LineChart | ||
withInnerLines={true} | ||
withOuterLines={false} | ||
withVerticalLines={false} | ||
// fromZero={true} | ||
withInnerLines={true} | ||
withOuterLines={false} | ||
withVerticalLines={false} | ||
// fromZero={true} | ||
data={{ | ||
labels: ["08:00", "09:00", "10:00", "11:00", "12:00", "13:00"], | ||
datasets: [ | ||
|
@@ -197,7 +168,7 @@ const Dashboard = () => { | |
} | ||
] | ||
}} | ||
width={Dimensions.get("window").width -30} // from react-native | ||
width={Dimensions.get("window").width - 30} // from react-native | ||
height={220} | ||
// yAxisLabel="" | ||
// yAxisSuffix="k" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,11 @@ jest.mock('@gluestack-ui/themed', () => ({ | |
}), | ||
})); | ||
|
||
jest.mock('expo-secure-store', () => ({ | ||
getItemAsync: jest.fn(), | ||
setItemAsync: jest.fn(), | ||
})); | ||
|
||
const renderWithProvider = (component) => { | ||
return render( | ||
<StyledProvider theme={Theme}> | ||
|
@@ -26,9 +31,24 @@ describe('Dashboard component', () => { | |
// expect(tree).toMatchSnapshot(); | ||
// }); | ||
|
||
const mockedData = { | ||
data: { | ||
details: { | ||
name: 'John Doe', | ||
contactNo: '1234567890', | ||
pronouns: 'He/Him', | ||
dob: '1990-01-01T00:00:00Z', // Make sure the format matches your component's expectations | ||
}, | ||
email: '[email protected]', | ||
occupiId: 'EMP12345', | ||
}, | ||
}; | ||
|
||
// Mock SecureStore getItemAsync to resolve with the mocked data | ||
require('expo-secure-store').getItemAsync.mockResolvedValueOnce(JSON.stringify(mockedData)); | ||
|
||
it('renders text correctly', () => { | ||
const { getByText } = renderWithProvider(<Dashboard />); | ||
expect(getByText('Hi Sabrina 👋')).toBeTruthy(); | ||
expect(getByText('Welcome to Occupi')).toBeTruthy(); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters