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

Feature/refreshtoken #272

Draft
wants to merge 19 commits into
base: dev
Choose a base branch
from
Draft

Feature/refreshtoken #272

wants to merge 19 commits into from

Conversation

Dan-Y-Ko
Copy link
Collaborator

@Dan-Y-Ko Dan-Y-Ko commented Oct 4, 2024

Description

This is an implementation using client components and fetching data on the client instead of the server. A lot of the project is broken because it'd take a lot of time and refactors to fix it all, so I just did some parts. Logging in works (logging out doesn't), directory page (fetching directory and setting avg hours) and features page works (only fetching features). Rest of the application is broken.

You can see the cookies in the browser and you can test the refresh token by deleting the access token and either going to features page (if you're on directory) or directory page (if you're on features). You can also test by changing the avg hours and submit it. Just a note, the loading spinner doesn't work and you have to refresh because I didn't implement the stuff you need to update the ui after an update

Issue link

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

vercel bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chingu-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 17, 2024 4:53pm

@Dan-Y-Ko
Copy link
Collaborator Author

Dan-Y-Ko commented Oct 4, 2024

There is currently an issue with the cookies not working properly. I have submitted a pr on the backend to resolve this


const getUserAsync = () =>
GET<User>("api/v1/users/me", token, "force-cache", "me");
export async function getUser() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we going to create a module also for this logic following the hexagonal pattern but in another pull request?

}
const [features, setFeatures] = useState<FeaturesList[]>([]);

useEffect(() => {
Copy link
Collaborator

@timothyrusso timothyrusso Oct 22, 2024

Choose a reason for hiding this comment

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

Could we do something like that maybe?

// Function to fetch features
const fetchFeatures = async () => {
try {
const response = await axiosInstance.get(
/api/v1/voyages/teams/${teamId}/features,
);
const transformedFeatures = transformData(response.data);
setFeatures(transformedFeatures);
} catch (error: any) {
console.error('Failed to fetch features', error);
}
};

useEffect(() => {
fetchFeatures(); // Simply call the function
}, [teamId]);

// }, []);

useEffect(() => {
const fetchDirectory = async () => {
Copy link
Collaborator

@timothyrusso timothyrusso Oct 22, 2024

Choose a reason for hiding this comment

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

Could we do something like thah maybe?

// Function to fetch team directory
const fetchDirectory = async () => {
try {
const response = await axiosInstance.get(/api/v1/teams/${teamId});
setTeamDirectory(response.data);
} catch (error: any) {
console.error('Failed to fetch team directory', error);
}
};

useEffect(() => {
fetchDirectory(); // Only call the function
}, [teamId]);

const { isAuthenticated } = useAuth();
const router = useRouter();

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we do something like that maybe?

// Function to fetch user and dispatch actions
const fetchUserAndDispatch = async () => {
try {
const data = await getUser();
dispatch(clientSignIn());

const currentDateInUserTimezone = formatInTimeZone(
  currentDate,
  data.timezone,
  "yyyy-MM-dd HH:mm:ss",
);

const userWithDate = {
  ...data,
  currentDate: new Date(currentDateInUserTimezone),
};

// Dispatch the getUserState action with the user object
dispatch(getUserState(userWithDate));

} catch (error) {
console.error('Failed to fetch user', error);
router.push(routePaths.signIn());
}
};

useEffect(() => {
fetchUserAndDispatch(); // Call the separated function
}, [dispatch, router]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants