diff --git a/src/assets/icon/cloud-download.png b/src/assets/icon/cloud-download.png new file mode 100644 index 0000000..bb70d1b Binary files /dev/null and b/src/assets/icon/cloud-download.png differ diff --git a/src/assets/icon/index.js b/src/assets/icon/index.js index 0205e8f..376130a 100644 --- a/src/assets/icon/index.js +++ b/src/assets/icon/index.js @@ -15,6 +15,8 @@ import QualityAsync from './total-quality-async.png'; import Failed from './total-failed.png' import NoAvailable from './no-available.png'; +import CloudDownload from './cloud-download.png'; + export { OCR, SmsAnnounce, @@ -32,4 +34,5 @@ export { AsyncIcon, QualityAsync, Failed, + CloudDownload } \ No newline at end of file diff --git a/src/screens/Sms/Verification/Section/Announcement.jsx b/src/screens/Sms/Verification/Section/Announcement.jsx index 43ab43a..848acbb 100644 --- a/src/screens/Sms/Verification/Section/Announcement.jsx +++ b/src/screens/Sms/Verification/Section/Announcement.jsx @@ -1,11 +1,632 @@ -import React from 'react' +import React, { useState, useRef, useEffect } from 'react'; +import Select from 'react-select' +import { ServerDownAnimation } from '../../../../assets/images'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faImage, faTimes, faCloudUploadAlt } from '@fortawesome/free-solid-svg-icons'; + + +const BASE_URL = process.env.REACT_APP_BASE_URL; +const API_KEY = process.env.REACT_APP_API_KEY; +const fileTypes = ["image/jpeg", "image/png"]; + +const SingleMessage = ({ applicationId, setApplicationId, messageId, setMessageId, phoneId, setPhoneId, isLoading, setIsLoading, isMobile, handleClick }) => { + const [inputValueApplication, setInputValueApplication] = useState(''); + const [selectedQuota, setSelectedQuota] = useState(0); + const [applicationIds, setApplicationIds] = useState([]); + const [errorMessage, setErrorMessage] = useState(''); + const [isServer, setIsServer] = useState(true); + + const applicationOptions = applicationIds.map(app => ({ + value: app.id, // This is what will be sent when an option is selected + label: app.name // This is what will be displayed in the dropdown + })); + + const handleInputChangeApplication = (inputValue) => { + setInputValueApplication(inputValue); + }; + + const handleApplicationChange = (selectedOption) => { + const selectedId = selectedOption.value; + const selectedApp = applicationIds.find(app => app.id === parseInt(selectedId)); + + setApplicationId(selectedOption ? selectedOption.value : ''); + + if (selectedApp) { + setSelectedQuota(selectedApp.quota); + } + }; + + useEffect(() => { + const fetchApplicationIds = async () => { + try { + setIsLoading(true); + const response = await fetch(`${BASE_URL}/application/list`, { + method: 'GET', + headers: { + 'accept': 'application/json', + 'x-api-key': API_KEY, + }, + }); + + if (!response.ok) { + throw new Error('Failed to fetch application IDs'); + } + + const data = await response.json(); + console.log('Response Data:', data); + + if (data.status_code === 200) { + setApplicationIds(data.details.data); + setIsServer(true); + } else { + setIsServer(false); + throw new Error(data.details.message || 'Failed to fetch application IDs'); + } + } catch (error) { + setErrorMessage(error.message || 'Error fetching application IDs'); + setIsServer(false); + } finally { + setIsLoading(false); + } + }; + + fetchApplicationIds(); + }, []); + + // Logic to handle the server down state should be inside the render logic, not around useEffect + if (!isServer) { + return ( +
+ Server Down Animation +

Server tidak dapat diakses

+

{errorMessage || 'Silakan periksa koneksi internet Anda atau coba lagi nanti.'}

+ +
+ ); + } + + return ( +
+ {/* Select Application ID */} +
+
+
+