Ignore:
Timestamp:
02/19/26 22:09:38 (5 months ago)
Author:
Mihail <mihail2.naumov@…>
Branches:
main
Children:
a508480
Parents:
546a194
Message:

Fixed auth issues in forger, component dialog name disappearance and other issues in forge page.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pages/forge/+Page.tsx

    r546a194 r3a9c59c  
    2626import ComponentDialog from '../../components/ComponentDialog';
    2727import ComponentDetailsDialog from '../../components/ComponentDetailsDialog';
    28 import {onAddNewBuild, onGetComponentDetails} from "../+Layout.telefunc";
     28import {onAddNewBuild, onGetAuthState, onGetComponentDetails} from "../+Layout.telefunc";
    2929import {onEditBuild} from "../dashboard/user/userDashboard.telefunc";
    3030import {BuildSlot, INITIAL_SLOTS} from "./types/buildTypes";
     
    157157    };
    158158
     159    // fix: changed text, new catch and removed setActiveSlotId(null), so the component name doesn't disappear.
    159160    const handleSelectComponent = async (component: any) => {
    160161        if (!activeSlotId) return;
     
    163164            let id = buildId;
    164165            if (!id) {
    165                 const result = await onAddNewBuild({
    166                     name: buildName.trim() || "New Build",
    167                     description: description || "Work in progress"
    168                 });
     166                let result;
     167                try {
     168                    result = await onAddNewBuild({
     169                        name: buildName.trim() || "New Build",
     170                        description: description || "Work in progress"
     171                    });
     172                } catch {
     173                    setSnackbar({
     174                        open: true,
     175                        message: 'Please log in first!',
     176                        severity: 'warning'
     177                    });
     178                    return;
     179                }
     180
    169181                id = typeof result === 'number' ? result : (result as any)?.buildId;
    170182                if (!id || !Number.isInteger(id) || id <= 0) {
    171183                    setSnackbar({
    172184                        open: true,
    173                         message: 'Failed to create draft build. Please try again.',
    174                         severity: 'error'
     185                        message: 'Please log in first!',
     186                        severity: 'warning'
    175187                    });
    176188                    return;
     
    198210            });
    199211        } finally {
    200             setActiveSlotId(null);
    201         }
    202     };
    203 
     212            // setActiveSlotId(null);
     213        }
     214    };
    204215    const handleRemovePart = async (slotId: string) => {
    205216        const slot = slots.find(s => s.id === slotId);
     
    320331    };
    321332
     333
     334    const [isLoggedIn, setIsLoggedIn] = useState(false);
     335    useEffect(() => {
     336        onGetAuthState().then(userData => {
     337            setIsLoggedIn(!!userData?.userId);
     338        });
     339    }, []);
     340
     341
    322342    const handleSubmit = () => {
     343        if (!isLoggedIn) {
     344            window.location.href = '/auth/login'
     345            return;
     346        }
     347
    323348        if (!buildName.trim()) {
    324349            setSnackbar({
     
    329354            return;
    330355        }
     356
    331357        if (!buildId) {
    332358            setSnackbar({
Note: See TracChangeset for help on using the changeset viewer.