Skip to content

Commit

Permalink
add linkedin functionality to pdf export
Browse files Browse the repository at this point in the history
Signed-off-by: Alex H <[email protected]>
  • Loading branch information
Alex H authored and Alex H committed Jan 6, 2025
1 parent 743acc1 commit ab6a740
Showing 1 changed file with 40 additions and 46 deletions.
86 changes: 40 additions & 46 deletions app/screens/PublicLinkScreen/PublicLinkScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ export default function PublicLinkScreen ({ navigation, route }: PublicLinkScree
console.log('ERROR GENERATING PDF:');
console.log(e);
}
if (rawPdf !== null) {
setShowExportToPdfButton(true);
}
};

fetchData();
Expand Down Expand Up @@ -137,46 +134,6 @@ export default function PublicLinkScreen ({ navigation, route }: PublicLinkScree
}
}

// Button press handler for exporting PDF
async function handleShareAsPdfButton() {
if (!isVerified) {
return displayNotVerifiedModal(); // Show modal if the credential isn't verified
}
// Prompt for confirmation before proceeding
const confirmed = await displayGlobalModal({
title: 'Are you sure?',
confirmText: 'Export to PDF',
cancelOnBackgroundPress: true,
body: (
<>
<Text style={mixins.modalBodyText}>
{publicLink !== null
? 'This will export your credential to PDF.'
: 'You must create a public link before exporting to PDF. The link will automatically expire 1 year after creation.'
}
</Text>
<Button
buttonStyle={mixins.buttonClear}
titleStyle={[mixins.buttonClearTitle, mixins.modalLinkText]}
containerStyle={mixins.buttonClearContainer}
title="What does this mean?"
onPress={() => Linking.openURL(`${LinkConfig.appWebsite.faq}#public-link`)}
/>
</>
)
});

if (!confirmed) return;

if (!publicLink) {
// If the public link isn't created, create it before generating the PDF
await createPublicLink();
}

// Now that we have the public link, generate the PDF
await handleGeneratePDF();
}

function displayNotVerifiedModal() {
return displayGlobalModal({
title: 'Unable to Share Credential',
Expand Down Expand Up @@ -291,6 +248,43 @@ export default function PublicLinkScreen ({ navigation, route }: PublicLinkScree
}
}

async function exportToPdf() {
if (!isVerified) {
return displayNotVerifiedModal(); // Show modal if the credential isn't verified
}

const confirmed = await displayGlobalModal({
title: 'Are you sure?',
confirmText: 'Export as PDF',
cancelOnBackgroundPress: true,
body: (
<>
<Text style={mixins.modalBodyText}>
{publicLink !== null
? 'This will export your credential to PDF.'
: 'This will export your credential as a PDF after creating a public link. The link will automatically expire 1 year after creation.'
}
</Text>
<Button
buttonStyle={mixins.buttonClear}
titleStyle={[mixins.buttonClearTitle, mixins.modalLinkText]}
containerStyle={mixins.buttonClearContainer}
title="What does this mean?"
onPress={() => Linking.openURL(`${LinkConfig.appWebsite.faq}#public-link`)}
/>
</>
)
});

if (!confirmed) return;
if (!publicLink) {
await createPublicLink();
}

// Now that we have the public link, generate the PDF
await handleGeneratePDF();
}

async function shareToLinkedIn() {
if (!isVerified) {
return displayNotVerifiedModal();
Expand Down Expand Up @@ -465,21 +459,21 @@ export default function PublicLinkScreen ({ navigation, route }: PublicLinkScree
)
}
<View style={styles.otherOptionsContainer}>
{showExportToPdfButton && <Button
<Button
title="Export To PDF"
buttonStyle={mixins.buttonIcon}
containerStyle={mixins.buttonIconContainer}
titleStyle={mixins.buttonIconTitle}
iconRight
onPress={handleShareAsPdfButton}
onPress={exportToPdf}
icon={
<Ionicons
name="document-text"
size={theme.iconSize}
color={theme.color.iconInactive}
/>
}
/>}
/>
<Button
title="Add to LinkedIn Profile"
buttonStyle={mixins.buttonIcon}
Expand Down

0 comments on commit ab6a740

Please sign in to comment.