SOC2.tsx143 lines · main
1// @ts-nocheck
2import { PermissionAction } from '@supabase/shared-types/out/constants'
3import { Download } from 'lucide-react'
4import { useState } from 'react'
5import { toast } from 'sonner'
6import { Button } from 'ui'
7import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
8import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
9
10import {
11 ScaffoldSection,
12 ScaffoldSectionContent,
13 ScaffoldSectionDetail,
14} from '@/components/layouts/Scaffold'
15import NoPermission from '@/components/ui/NoPermission'
16import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton'
17import { getDocument } from '@/data/documents/document-query'
18import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
19import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
20import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
21import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
22
23export const SOC2 = () => {
24 const { data: organization } = useSelectedOrganizationQuery()
25 const slug = organization?.slug
26
27 const { mutate: sendEvent } = useSendEventMutation()
28 const { can: canReadSubscriptions, isLoading: isLoadingPermissions } = useAsyncCheckPermissions(
29 PermissionAction.BILLING_READ,
30 'stripe.subscriptions'
31 )
32 const { hasAccess: hasAccessToSoc2Report, isLoading: isLoadingEntitlement } =
33 useCheckEntitlements('security.soc2_report')
34
35 const [isOpen, setIsOpen] = useState(false)
36
37 const fetchSOC2 = async (orgSlug: string) => {
38 try {
39 const soc2Link = await getDocument({ orgSlug, docType: 'soc2-type-2-report' })
40 if (soc2Link?.fileUrl) window.open(soc2Link.fileUrl, '_blank')
41 setIsOpen(false)
42 } catch (error: unknown) {
43 const message = error instanceof Error ? error.message : 'Unknown error occurred'
44 toast.error(`Failed to download SOC2 report: ${message}`)
45 }
46 }
47
48 const handleDownloadClick = () => {
49 if (!slug) return
50
51 sendEvent({
52 action: 'document_view_button_clicked',
53 properties: { documentName: 'SOC2' },
54 groups: { organization: slug },
55 })
56 setIsOpen(true)
57 }
58
59 return (
60 <ScaffoldSection className="py-12">
61 <ScaffoldSectionDetail>
62 <h4 className="mb-5">SOC2 Type 2</h4>
63 <div className="space-y-2 text-sm text-foreground-light [&_p]:m-0">
64 <p>
65 Organizations on Team Plan or above have access to our most recent SOC2 Type 2 report.
66 </p>
67 </div>
68 </ScaffoldSectionDetail>
69 <ScaffoldSectionContent>
70 {isLoadingPermissions || isLoadingEntitlement ? (
71 <div className="@lg:flex items-center justify-center h-full">
72 <ShimmeringLoader className="w-24" />
73 </div>
74 ) : !canReadSubscriptions ? (
75 <NoPermission resourceText="access our SOC2 Type 2 report" />
76 ) : !hasAccessToSoc2Report ? (
77 <div className="@lg:flex items-center justify-center h-full">
78 <UpgradePlanButton
79 variant="default"
80 plan="Team"
81 source="org-documents-soc2"
82 featureProposition="download the SOC2 Type 2report"
83 />
84 </div>
85 ) : (
86 <div className="@lg:flex items-center justify-center h-full">
87 <Button
88 type="default"
89 icon={<Download />}
90 onClick={handleDownloadClick}
91 disabled={!slug}
92 >
93 Download SOC2 Type 2 Report
94 </Button>
95 </div>
96 )}
97 <ConfirmationModal
98 visible={isOpen}
99 size="large"
100 title="Non-Disclosure Agreement to access Briven's SOC2 Report"
101 confirmLabel="I agree"
102 confirmLabelLoading="Downloading"
103 onCancel={() => setIsOpen(false)}
104 onConfirm={() => {
105 if (slug) fetchSOC2(slug)
106 }}
107 >
108 <ol className="list-decimal list-inside text-sm text-foreground-light pl-30">
109 <li>The information that you are about to access is confidential.</li>
110 <li>
111 Your access to our SOC 2 materials is governed by confidentiality obligations
112 contained in the agreement between Briven, Inc ("Briven", "we", "our" or "us") and
113 the Briven customer that has authorized you to access our platform to obtain this
114 information (our "Customer").
115 </li>
116 <li>
117 You must ensure that you treat the information in our SOC 2 materials in accordance
118 with those confidentiality obligations, as communicated to you by the Customer.
119 </li>
120 <li>
121 By clicking "I agree" below or otherwise accessing our SOC 2 materials, you:
122 <ol className="list-[lower-roman] list-inside pl-4">
123 <li>acknowledge that you have read and understood this Confidentiality Notice;</li>
124 <li>
125 confirm that you have been authorized by the Customer to access this information,
126 and your use of our SOC 2 materials is subject to the confidentiality obligations
127 owed by the Customer to us.
128 </li>
129 </ol>
130 </li>
131 <li>
132 This Confidentiality Notice does not substitute or supersede any agreement between us
133 and the Customer, or any internal rules or policies that the Customer requires you to
134 comply with in your access to and use of confidential information. However, your
135 failure to comply with this Confidentiality Notice may be used to determine whether
136 the Customer has complied with its confidentiality obligations to us.
137 </li>
138 </ol>
139 </ConfirmationModal>
140 </ScaffoldSectionContent>
141 </ScaffoldSection>
142 )
143}