mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
/**
|
|
* Organization proposal management hook
|
|
* Handles proposal modal state and submission logic
|
|
* Separated from other concerns for better SRP
|
|
*/
|
|
|
|
import { useCallback, useMemo, useState } from 'react';
|
|
import type { Organization, ResourceFlow } from '@/types.ts';
|
|
import { useCreateProposal } from '@/hooks/api/useProposalsAPI.ts';
|
|
import { useAuth } from '@/contexts/AuthContext.tsx';
|
|
|
|
interface ProposalModalContext {
|
|
targetOrg: Organization;
|
|
resource: ResourceFlow;
|
|
resourceType: 'input' | 'output';
|
|
}
|
|
|
|
export const useOrganizationProposals = (organization: Organization | undefined) => {
|
|
const { user, isAuthenticated } = useAuth();
|
|
const createProposalMutation = useCreateProposal();
|
|
const [isProposalModalOpen, setIsProposalModalOpen] = useState(false);
|
|
const [proposalContext, setProposalContext] = useState<ProposalModalContext | null>(null);
|
|
|
|
const openProposalModal = useCallback(
|
|
(resource: ResourceFlow, resourceType: 'input' | 'output') => {
|
|
if (!organization) return;
|
|
setProposalContext({ targetOrg: organization, resource, resourceType });
|
|
setIsProposalModalOpen(true);
|
|
},
|
|
[organization]
|
|
);
|
|
|
|
const closeProposalModal = useCallback(() => {
|
|
setIsProposalModalOpen(false);
|
|
setProposalContext(null);
|
|
}, []);
|
|
|
|
const submitProposal = useCallback(
|
|
(message: string) => {
|
|
if (!proposalContext || !user) return;
|
|
|
|
createProposalMutation.mutate({
|
|
from_org_id: user.id,
|
|
to_org_id: proposalContext.targetOrg.ID,
|
|
resource_id: proposalContext.resource.ID,
|
|
resource_type: proposalContext.resourceType,
|
|
resource_name: proposalContext.resource.Type,
|
|
message: message,
|
|
});
|
|
closeProposalModal();
|
|
},
|
|
[proposalContext, user, createProposalMutation, closeProposalModal]
|
|
);
|
|
|
|
const proposalState = useMemo(
|
|
() => ({
|
|
isModalOpen: isProposalModalOpen,
|
|
modalContext: proposalContext,
|
|
}),
|
|
[isProposalModalOpen, proposalContext]
|
|
);
|
|
|
|
const actions = useMemo(
|
|
() => ({
|
|
openProposalModal,
|
|
closeProposalModal,
|
|
submitProposal,
|
|
}),
|
|
[openProposalModal, closeProposalModal, submitProposal]
|
|
);
|
|
|
|
return {
|
|
proposalState,
|
|
actions,
|
|
};
|
|
};
|