-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28e8d22
commit 40f9c18
Showing
2 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React from 'react'; | ||
import { Button } from '@/components/ui/button'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '@/components/ui/dialog'; | ||
import { Twitter, Linkedin, Share2 } from 'lucide-react'; | ||
import { JobType } from '@/types/jobs.types'; | ||
|
||
interface ShareOption { | ||
name: string; | ||
icon: React.ReactNode; | ||
shareFunction: (job: JobType) => void; | ||
} | ||
|
||
const shareOptions: ShareOption[] = [ | ||
{ | ||
name: 'Twitter', | ||
icon: <Twitter className="h-5 w-5" />, | ||
shareFunction: (job: JobType) => { | ||
const text = encodeURIComponent( | ||
`Check out this job posting: ${job.title} at ${job.companyName}` | ||
); | ||
const url = encodeURIComponent(window.location.href); | ||
window.open( | ||
`https://twitter.com/intent/tweet?text=${text}&url=${url}`, | ||
'_blank' | ||
); | ||
}, | ||
}, | ||
{ | ||
name: 'LinkedIn', | ||
icon: <Linkedin className="h-5 w-5" />, | ||
shareFunction: (job: JobType) => { | ||
const url = encodeURIComponent(window.location.href); | ||
const title = encodeURIComponent(job.title); | ||
const summary = encodeURIComponent( | ||
`Exciting opportunity: ${job.title} at ${job.companyName}. Check out the details!` | ||
); | ||
window.open( | ||
`https://www.linkedin.com/sharing/share-offsite/?url=${url}&title=${title}&summary=${summary}`, | ||
'_blank' | ||
); | ||
}, | ||
}, | ||
{ | ||
name: 'WhatsApp', | ||
icon: <Share2 className="h-5 w-5" />, // Using Share2 as a placeholder, replace with WhatsApp icon if available | ||
shareFunction: (job: JobType) => { | ||
const text = encodeURIComponent( | ||
`Check out this job posting: ${job.title} at ${job.companyName} - ${window.location.href}` | ||
); | ||
window.open(`https://wa.me/?text=${text}`, '_blank'); | ||
}, | ||
}, | ||
]; | ||
|
||
export const ShareJobDialog = ({ job }: { job: JobType }) => { | ||
return ( | ||
<Dialog> | ||
<DialogTrigger asChild> | ||
<Button | ||
variant="outline" | ||
size="sm" | ||
className="px-4 py-2 h-fit gap-2 flex items-center" | ||
> | ||
Share Job <Share2 size={16} /> | ||
</Button> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-md"> | ||
<DialogHeader> | ||
<DialogTitle>Share Job</DialogTitle> | ||
</DialogHeader> | ||
<div className="flex flex-col space-y-4"> | ||
{shareOptions.map((option) => ( | ||
<Button | ||
key={option.name} | ||
variant="outline" | ||
className="w-full justify-start gap-2" | ||
onClick={() => option.shareFunction(job)} | ||
> | ||
{option.icon} | ||
Share on {option.name} | ||
</Button> | ||
))} | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters