Improve code - Realtime Quota
This commit is contained in:
		
							parent
							
								
									47115a8ebb
								
							
						
					
					
						commit
						77e4f0cf4d
					
				@ -215,6 +215,7 @@ const Compare = () => {
 | 
				
			|||||||
            setVerified(data.details.data.result.verified);
 | 
					            setVerified(data.details.data.result.verified);
 | 
				
			||||||
            setResultImageLabel(selectedImageName)
 | 
					            setResultImageLabel(selectedImageName)
 | 
				
			||||||
            setResultCompareImageLabel(selectedCompareImageName)
 | 
					            setResultCompareImageLabel(selectedCompareImageName)
 | 
				
			||||||
 | 
					            setSelectedQuota(data.details.data.result.quota)
 | 
				
			||||||
            setShowResult(true);
 | 
					            setShowResult(true);
 | 
				
			||||||
            console.log('Comparison successful:', data);
 | 
					            console.log('Comparison successful:', data);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -231,6 +231,12 @@ const Enroll = () => {
 | 
				
			|||||||
            const result = await response.json();
 | 
					            const result = await response.json();
 | 
				
			||||||
            console.log('Enrollment response:', result);
 | 
					            console.log('Enrollment response:', result);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					            // Update quota based on the response data
 | 
				
			||||||
 | 
					            if (result.details && result.details.data && result.details.data.quota !== undefined) {
 | 
				
			||||||
 | 
					                const updatedQuota = result.details.data.quota;
 | 
				
			||||||
 | 
					                setSelectedQuota(updatedQuota); // Update the state with the new quota
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
            if (result.details && result.details.data && result.details.data.image_url) {
 | 
					            if (result.details && result.details.data && result.details.data.image_url) {
 | 
				
			||||||
                const imageFileName = result.details.data.image_url.split('/').pop();
 | 
					                const imageFileName = result.details.data.image_url.split('/').pop();
 | 
				
			||||||
                console.log('Image URL:', result.details.data.image_url);
 | 
					                console.log('Image URL:', result.details.data.image_url);
 | 
				
			||||||
@ -671,6 +677,7 @@ const Enroll = () => {
 | 
				
			|||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
            <div className="form-group row align-items-center">
 | 
					            <div className="form-group row align-items-center">
 | 
				
			||||||
                <div className="col-md-6">
 | 
					                <div className="col-md-6">
 | 
				
			||||||
                    <input
 | 
					                    <input
 | 
				
			||||||
 | 
				
			|||||||
@ -230,15 +230,25 @@ const Verify = () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        const data = await response.json();
 | 
					        const data = await response.json();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Log the response data for debugging
 | 
				
			||||||
 | 
					        console.log('API Response Data:', data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (response.ok) {
 | 
					        if (response.ok) {
 | 
				
			||||||
            if (data.details && data.details.data && data.details.data.result && data.details.data.result.image_url) {
 | 
					            if (data.details && data.details.data && data.details.data.result) {
 | 
				
			||||||
                const imageFileName = data.details.data.result.image_url.split('/').pop();
 | 
					                const result = data.details.data.result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Update selectedQuota with the quota received from API
 | 
				
			||||||
 | 
					                setSelectedQuota(result.quota);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (result.image_url) {
 | 
				
			||||||
 | 
					                    const imageFileName = result.image_url.split('/').pop();
 | 
				
			||||||
                    await fetchImage(imageFileName);
 | 
					                    await fetchImage(imageFileName);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                setShowResult(true);
 | 
					                setShowResult(true);
 | 
				
			||||||
            setVerified(data.details.data.result.verified);
 | 
					                setVerified(result.verified);
 | 
				
			||||||
                setResultImageLabel(selectedImageName);
 | 
					                setResultImageLabel(selectedImageName);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            const errorMessage = data.message || data.detail || data.details?.message || 'An unknown error occurred.';
 | 
					            const errorMessage = data.message || data.detail || data.details?.message || 'An unknown error occurred.';
 | 
				
			||||||
            setErrorMessage(errorMessage);
 | 
					            setErrorMessage(errorMessage);
 | 
				
			||||||
@ -251,6 +261,7 @@ const Verify = () => {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const fetchImage = async (imageFileName) => {
 | 
					  const fetchImage = async (imageFileName) => {
 | 
				
			||||||
    setIsLoading(true);
 | 
					    setIsLoading(true);
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
@ -745,21 +756,6 @@ const Verify = () => {
 | 
				
			|||||||
              onChange={(e) => handleImageUpload(e.target.files[0])}
 | 
					              onChange={(e) => handleImageUpload(e.target.files[0])}
 | 
				
			||||||
            />
 | 
					            />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            {/* Display selected file info */}
 | 
					 | 
				
			||||||
            {selectedImageName && (
 | 
					 | 
				
			||||||
              <div className="mt-3">
 | 
					 | 
				
			||||||
                <p><strong>File:</strong> {selectedImageName}</p>
 | 
					 | 
				
			||||||
                {file && (
 | 
					 | 
				
			||||||
                  <p style={styles.fileSize}>
 | 
					 | 
				
			||||||
                    Size: {formatFileSize(file.size)}
 | 
					 | 
				
			||||||
                  </p>
 | 
					 | 
				
			||||||
                )}
 | 
					 | 
				
			||||||
                <button className="btn btn-danger" onClick={handleImageCancel}>
 | 
					 | 
				
			||||||
                  <FontAwesomeIcon icon={faTimes} className="me-2" />Cancel
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
              </div>
 | 
					 | 
				
			||||||
            )}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            {/* Error Message */}
 | 
					            {/* Error Message */}
 | 
				
			||||||
            {uploadError && <small style={styles.uploadError}>{uploadError}</small>}
 | 
					            {uploadError && <small style={styles.uploadError}>{uploadError}</small>}
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 | 
				
			|||||||
@ -53,6 +53,9 @@ const Verify = () => {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
                const data = await response.json();
 | 
					                const data = await response.json();
 | 
				
			||||||
 | 
					                // Log response data
 | 
				
			||||||
 | 
					                console.log('Response Data:', data);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
                if (data.status_code === 200) {
 | 
					                if (data.status_code === 200) {
 | 
				
			||||||
                    setApplicationIds(data.details.data);
 | 
					                    setApplicationIds(data.details.data);
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
@ -186,6 +189,7 @@ const Verify = () => {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
            if (result.status_code === 201) {
 | 
					            if (result.status_code === 201) {
 | 
				
			||||||
                const responseData = result.details.data?.['data-ktp'] || {};
 | 
					                const responseData = result.details.data?.['data-ktp'] || {};
 | 
				
			||||||
 | 
					                const updateQuota = result.details.data.quota
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
                const data = {
 | 
					                const data = {
 | 
				
			||||||
                    nik: responseData.nik || 'N/A',
 | 
					                    nik: responseData.nik || 'N/A',
 | 
				
			||||||
@ -205,6 +209,8 @@ const Verify = () => {
 | 
				
			|||||||
                    imageUrl: result.details.data?.image_url || '', // Properly access image_url
 | 
					                    imageUrl: result.details.data?.image_url || '', // Properly access image_url
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                setSelectedQuota(updateQuota)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
                console.log('Image URL from OCR:', result.details.data?.image_url); // Log the image URL correctly
 | 
					                console.log('Image URL from OCR:', result.details.data?.image_url); // Log the image URL correctly
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
                setData(data);
 | 
					                setData(data);
 | 
				
			||||||
@ -300,10 +306,10 @@ const Verify = () => {
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
        uploadArea: {
 | 
					        uploadArea: {
 | 
				
			||||||
            backgroundColor: '#e6f2ff',
 | 
					            backgroundColor: '#e6f2ff',
 | 
				
			||||||
            height: !isMobile? '30svh' : '50svh',
 | 
					            height: !isMobile? '43svh' : '50svh',
 | 
				
			||||||
            cursor: 'pointer',
 | 
					            cursor: 'pointer',
 | 
				
			||||||
            marginTop: '1rem',
 | 
					            marginTop: '1rem',
 | 
				
			||||||
            paddingTop: '22px',
 | 
					            padding: '3rem',
 | 
				
			||||||
            display: 'flex',
 | 
					            display: 'flex',
 | 
				
			||||||
            flexDirection: 'column',
 | 
					            flexDirection: 'column',
 | 
				
			||||||
            justifyContent: 'center',
 | 
					            justifyContent: 'center',
 | 
				
			||||||
 | 
				
			|||||||
@ -186,6 +186,7 @@ const Verify = () => {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
            if (result.status_code === 201) {
 | 
					            if (result.status_code === 201) {
 | 
				
			||||||
                const responseData = result.details.data?.['data-npwp'] || {};
 | 
					                const responseData = result.details.data?.['data-npwp'] || {};
 | 
				
			||||||
 | 
					                const updateQuota = result.details.data.quota
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                const data = {
 | 
					                const data = {
 | 
				
			||||||
                    npwp: responseData.npwp || 'N/A',
 | 
					                    npwp: responseData.npwp || 'N/A',
 | 
				
			||||||
@ -195,6 +196,8 @@ const Verify = () => {
 | 
				
			|||||||
                    imageUrl: result.details.data?.image_url || '', // Properly access image_url
 | 
					                    imageUrl: result.details.data?.image_url || '', // Properly access image_url
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                setSelectedQuota(updateQuota)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
                console.log('Image URL from OCR:', result.details.data?.image_url); // Log the image URL correctly
 | 
					                console.log('Image URL from OCR:', result.details.data?.image_url); // Log the image URL correctly
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
                setData(data);
 | 
					                setData(data);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user