// Context
import { LoadingStatusContext } from '@freesewing/react/context/LoadingStatus'
// Hooks
import React, { useState, useContext } from 'react'
import { useAccount } from '@freesewing/react/hooks/useAccount'
import { useBackend } from '@freesewing/react/hooks/useBackend'
// Components
import { SaveIcon } from '@freesewing/react/components/Icon'
import { StringInput } from '@freesewing/react/components/Input'
const labels = {
instagram: 'Instagram',
mastodon: 'Mastodon',
reddit: 'Reddit',
twitch: 'Twitch',
tiktok: 'TikTok',
website: 'Website',
}
/**
* A component to manage the user's Instagram handle in their account data
*
* @component
* @returns {JSX.Element}
*/
export const Instagram = () =>
/**
* A component to manage the user's Mastodon handle in their account data
*
* @component
* @returns {JSX.Element}
*/
export const Mastodon = () =>
/**
* A component to manage the user's Reddit handle in their account data
*
* @component
* @returns {JSX.Element}
*/
export const Reddit = () =>
/**
* A component to manage the user's Twitch handle in their account data
*
* @component
* @returns {JSX.Element}
*/
export const Twitch = () =>
/**
* A component to manage the user's Tiktok handle in their account data
*
* @component
* @returns {JSX.Element}
*/
export const Tiktok = () =>
/**
* A component to manage the user's website URL in their account data
*
* @component
* @returns {JSX.Element}
*/
export const Website = () =>
/*
* Component for the account/social/[platform] page
*
* @param {object} props - All React props
* @param {string} platform - One of the keys in the labels object above
*/
const Platform = ({ platform = false }) => {
// Hooks
const { account, setAccount } = useAccount()
const backend = useBackend()
const { setLoadingStatus } = useContext(LoadingStatusContext)
// State
const [platformId, setPlatformId] = useState(account.data[platform] || '')
if (!labels || !labels[platform]) return
Not a supported platform
// Helper method to save changes
const save = async () => {
setLoadingStatus([true, 'Saving linked identity'])
const data = { data: {} }
data.data[platform] = platformId
const [status, body] = await backend.updateAccount(data)
if (status === 200 && body.result === 'success') {
setAccount(body.account)
setLoadingStatus([true, `Saved your ${labels[platform]} info`, true, true])
} else setLoadingStatus([true, 'Something went wrong. Please report this', true, true])
}
return (
val.length > 0}
placeholder={'joostdecock'}
/>
)
}