Hooks & Tanstack Query Integration #222
Labels
Frontend
Frontend Related Issue
⚡Important
High-impact issue that needs to be resolved before the next release
New Feature
New feature to be implemented
Milestone
Goal
Centralize API calls into domain‐specific hooks, leveraging
Tanstack Query
for caching and reactivity. This includes fetching dynamic visitor fields and handling them in a typed manner. Keep a “one endpoint → one hook” principle for clarity and testability.Detailed Guidelines
src/hooks/documentAccess/
.useDocumentAccess
for GET link details,useVisitorSubmission
for POST visitor data/password.useQuery
for fetching link info (likeGET /api/public_links/[linkId]
).useMutation
forPOST
calls (likePOST /api/public_links/[linkId]/access
).visitorFields
in JSON along with flags likepasswordProtected
, but also store name/email columns (depending on how it's setup). The hooks should parse and store them in state appropriately.Tasks
useDocumentAccess.ts
:useQuery(['documentAccess', linkId], ...)
to fetch link data.linkData
should contain:visitorFields
(an array or object of keys: e.g.,["name","email"]
),passwordProtected: boolean
,useVisitorSubmission.ts
:useMutation
for sending{ visitorData, password? }
toPOST /api/public_links/[linkId]/access
.visitorFields
and merges them if it has columns for name/email.AccessPage.tsx
,VisitorInfoModal.tsx
) to call these hooks instead of directaxios
.useDocumentAccess
,useVisitorSubmission
,useDocumentAnalytics
(if needed), etc.src/hooks/
for domain‐based folders:documentAccess
,documents
,auth
, etc.AccessPage.tsx
by calling a “direct access” method fromuseDocumentAccess
.The text was updated successfully, but these errors were encountered: