Skip to content

Commit

Permalink
add local code
Browse files Browse the repository at this point in the history
  • Loading branch information
SamratSahoo committed Oct 4, 2024
1 parent a64acc9 commit b4f623e
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions mobile/screens/User/UserDashboardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,38 @@ export default function UserDashboardScreen(props: any) {
const [shotReminderVisible, setShotReminderVisible] = useState<boolean>(false);
const [calculatedShotDate, setCalculatedShotDate] = useState<Date>();

const checkRabiesShot = async () => {
const checkRabiesShot = async (animalInformation: ServiceAnimal) => {
if (birthdayModalVisible)
return

if (!animalInfo?.dateOfRabiesShot || !animalInfo?.rabiesShotTimeInterval)
if (!animalInformation)
animalInformation = (await ErrorWrapper({
functionToExecute: userGetAnimal,
errorHandler: setError,
})) as ServiceAnimal;

if (!animalInformation?.dateOfRabiesShot || !animalInformation?.rabiesShotTimeInterval)
return

const newDate = new Date(animalInfo?.dateOfRabiesShot);
newDate.setFullYear(newDate.getFullYear() + (animalInfo?.rabiesShotTimeInterval ?? 0));
const newDate = new Date(animalInformation?.dateOfRabiesShot);
newDate.setFullYear(newDate.getFullYear() + (animalInformation?.rabiesShotTimeInterval ?? 0));
setCalculatedShotDate(newDate as Date);

if (newDate > new Date())
return

setShotReminderVisible(true);
const newAnimal = await userUpdateAnimal(animalInfo?.name,
animalInfo?.totalHours,
animalInfo?.subHandler,
animalInfo?.dateOfBirth,
animalInfo?.dateOfAdoption,
const newAnimal = await userUpdateAnimal(animalInformation?.name,
animalInformation?.totalHours,
animalInformation?.subHandler,
animalInformation?.dateOfBirth,
animalInformation?.dateOfAdoption,
newDate,
animalInfo?.rabiesShotTimeInterval,
animalInfo?.dateOfTrainingClass,
animalInfo?.microchipExpiration,
animalInfo?.checkUpDate,
animalInfo?.profileImage);
animalInformation?.rabiesShotTimeInterval,
animalInformation?.dateOfTrainingClass,
animalInformation?.microchipExpiration,
animalInformation?.checkUpDate,
animalInformation?.profileImage);

if (newAnimal) {
setAnimalInfo(newAnimal);
Expand Down Expand Up @@ -110,7 +116,7 @@ export default function UserDashboardScreen(props: any) {
if ((new Date(animal?.dateOfBirth as Date)).getMonth() == new Date().getMonth() && new Date(animal?.dateOfBirth as Date).getDate() == new Date().getDate()) {
setBirthdayModalVisible(true);
} else {
await checkRabiesShot()
await checkRabiesShot(animal)
}


Expand Down Expand Up @@ -143,7 +149,8 @@ export default function UserDashboardScreen(props: any) {


useEffect(() => {
checkRabiesShot().then().catch()

checkRabiesShot(animalInfo as ServiceAnimal).then().catch()
}, [birthdayModalVisible])


Expand Down

0 comments on commit b4f623e

Please sign in to comment.